n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(list(map(int,input().split())))
   
for i in range(q):

    while bc[i][0] in a:
        a[a.index(bc[i][0])] = bc[i][1]
    print(sum(a))