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

aDict = dict()
for aElement in A:
    if aElement not in aDict:
        aDict[aElement] = 0
    aDict[aElement] += 1

for _ in range(Q):
    b, c = map(int, input().split())
    if c not in aDict:
        aDict[c] = 0
    aDict[c] += aDict.pop(b, 0)
    print(sum([k * v for k, v in aDict.items()]))
