from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()])
Q = int(stdin.readline().rstrip())
BC = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]
ans = []
for bc in BC:
    if bc[1] not in A:
        A[bc[1]] = A[bc[0]]
    else:
        A[bc[1]] += A[bc[0]]
    A.pop(bc[0], None)
    ans.append(sum(k*v for k, v in A.items()))
for a in ans:
    print(a)