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

b = [0 for i in range(q)]
c = [0 for i in range(q)]
for i in range(q):
    b[i],c[i] = list(map(int,input().split()))

for i in range(q):
    a = [c[i] if x == b[i] else x for x in a]
    print(sum(a))
