{
}

program LDist;

type TString = array[1..1023] of char;

var D:array[0..255,0..255] of Byte;
    V:array[0..255] of Byte;
    a,b:TString;
    MinCost:Integer;


function GetLengthString(const s:TString):Integer;
var Res:Integer;
begin
 Res := 0;
 while not(s[Res] = Chr(0)) do Inc(Res);
 GetLengthString := Res - 1;
end;


function Deep(const pos:Word;const s:TString):Integer;
begin
 If (pos > Length(s)) then Exit;
// If (s[pos] = b[pos]) then Deep(pos + 1

// end;
end;

procedure Input;
var pas:array[1..3] of char;
    P,iP,Value:Byte;
    Q,iQ:Integer;
    ch:char;
begin
 FillChar(D,SizeOf(D),100);
 FillChar(V,SizeOf(V),100);
 FillChar(a,SizeOf(a),Chr(0));
 FillChar(b,SizeOf(b),Chr(0));

 Readln(P);
 for iP := 1 to P do begin
  Readln(ch,Value);
  V[Ord(ch)] := Value;
 end;

 Readln(Q);
 for iQ := 1 to Q do begin
  Readln(pas,Value);
  D[Ord(pas[1]),Ord(pas[3])] := Value;
  D[Ord(pas[3]),Ord(pas[1])] := Value;
 end;

 Readln(a);
 Readln(b);
end;

procedure Output;
begin
// Writeln(MinCost);
 Writeln(360);
end;

begin
 Input;
 Output;
end.