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

from collections import Counter
a = Counter(A)
x = 0

for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0

    s = sum(item*a[item] for item in a)
    # s = 0
    # for i,v in a.items():
    #     if v != 0:
    #         s += i*v
    print(s)