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

d = dict()
sa = set(a)
ans = sum(a)

for i in sa:
    d[i] = a.count(i)

for j in range(q):
    b,c = map(int,input().split())
    if (b in d) == True:
        ans += (c-b)*d[b]
    if (c in d) == True:
        x = d[c] + d[b]
        d[c] = x
        d[b] = 0
    else:
        if (b in d) == True:
            d[c] = d[b]
            d[b] = 0
    print(ans)