n = int(input())
a = list(map(int,input().split()))
q = int(input())
res = []
for i in range(q):
    b,c = map(int,input().split())
    while b in a:
        a.remove(b)
        a.append(c)
    res.append(sum(a))

for x in res:
    print(x)
