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

A_dict = {}
for a in A:
    A_dict[a] = A.count(a)

A_sum = sum(A)
for b, c in zip(B, C):
    if b in A_dict.keys():
        n = A_dict[b]
    else:
        n = 0
    A_dict[b] = 0
    if c in A_dict.keys():
        A_dict[c] += n
    else:
        A_dict[c] = n
    A_sum += (c - b) * n
    print(A_sum)
