n = int(input())
arr = list(map(int, input().split()))
k = int(input())
s = sum(arr)
d = {}
for i in arr:
    d[i] = arr.count(i)
for _ in range(k):
    v = 0
    a,b = map(int, input().split())
    if a in d:
        d[b] = d[a]
        del d[a]
    v = d[b]
    s = s - (a*v) + (b*v)
    print(s)