import math

n = int(input())
aL = list(map(int, input().split(" ")))
q = int(input())
bcL = [list(map(int, input().split(" "))) for _ in range(q)]

d = {}
for i in range(n):
    if aL[i] in d:
        d[aL[i]] += 1
    else:
        d[aL[i]] = 1

for b, c in bcL:
    if b in d.keys():
        if c in d:
            d[c] += d[b]
        else:
            d[c] = d[b]
        del d[b]

    _sum = 0
    for k, v in d.items():
        _sum += k * v
    print(_sum)