N = int(input())
A = list(map(int,input().split()))
Q = int(input())
l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))
for i in range(Q):
    if l[i][0] in A:
        index_num = [n for n, v in enumerate(A) if v == l[i][0]]
        for j in index_num:
            A[j]=l[i][1]
    print(sum(A))
