N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B, C = [], []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

ans = sum(A)
d = dict()
for i, a in enumerate(A):
    if a not in d:
        d[a] = ()
    d[a] += (i,)

for b, c in zip(B, C):
    if b not in d:
        print(ans)
        continue
    ans += len(d[b]) * (c-b)
    if c not in d:
        d[c] = ()
    d[c] = d[c] + d[b]
    d[b] = ()
    print(ans)