n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = []
ans = []
for i in range(q):
    bc = list(map(int,input().split()))
    #bc.append(list(map(int,input().split())))
    #while bc[i][0] in a:
        #a[a.index(bc[i][0])] = bc[i][1]
    aa = [bc[1] if bc[0] == a[j] else a[j] for j in range(len(a))]
    a = aa
    ans.append(sum(aa))
for i in range(len(ans)):
    print(ans[i])