sumAlist = []
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
sumA = sum(A)
for i in range(Q):
    B,C = map(int,input().split())
    dif = C-B
    sumA += dif*A.count(B)
    sumAlist.append(sumA)
    Areplace = [C if i == B else i for i in A]
    A = Areplace
for i in range(Q):
    print(sumAlist[i])