from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0
