n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = [0] * q
c = [0] * q
ans = sum(a)
number = [0] * 100000
for i in range(q):
    b[i],c[i] = map(int,input().split())
for i in range(n):
    number[a[i]] += 1
for i in range(q):
    if number[b[i]] > 0:
        ans += (c[i] - b[i]) * number[b[i]]
        number[c[i]] = number[b[i]]    
        number[b[i]] = 0
    print(ans)