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