N = int(input())
A = list(map(int, input().split()))
Q = int(input())

dictA = {}

for z in A:
    dictA.setdefault(z, 0)
    dictA[z] += 1


BC = [list(map(int, input().split())) for i in range(Q)]
for x in BC:
    if x[0] in dictA:
        if x[1] in dictA:
            dictA[x[1]] += dictA[x[0]]
        else:
            dictA[x[1]] = dictA[x[0]]
        del dictA[x[0]]

    sumA = 0
    for k, v in dictA.items():
        sumA += k * v
    print(sumA)
