import sys

def retList(target, A):
  split = target.split()
  ret = []
  for j, v in enumerate(A):
    #print(j, v, split[0], split[1])
    if v == int(split[0]):
      #print("変換")
      v = int(split[1])
    ret.append(v)
  return ret

N = int(input())
#print(N)

a = input().split()
A = [int(b.strip()) for b in a]
#print(A)

Q =  int(input())
#print(Q)

B = sys.stdin.readlines()
C = [b.strip() for b in B]
#print(C)

for i in range(Q):
  target = C[i]
  if i == 0:
    ret = retList(target, A)
  else:
    ret = retList(target, ret)
  print(sum(ret))
