n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = ''
for i in range(n):
    A += ' ' + str(a[i])

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    s = A.replace(str(B[i]), str(C[i]))
    cnt = A.count(str(B[i]))
    ans += (C[i]-B[i])*cnt
    print(ans)
    A = s
