n = int(input())
ali = list(map(int, input().split()))
q = int(input())

opelates = []
for _ in range(q):
    opelates.append(list(map(int, input().split())))

for op in opelates:
    pre = op[0]
    nex = op[1]
    for i in range(n):
        if ali[i] == pre:
            ali[i] = nex
    print(sum(ali))