N = int(input())
lsn = list(map(int, input().split()))
Q = int(input())
res = 0
for i in range(Q):
    b, c = map(int, input().split())
    if b in lsn:
        for _ in range(lsn.count(b)):
            lsn.append(c)
            lsn.remove(b)
    print(sum(lsn))