import numpy as np

n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    if(b in a):
        a=[c if i == b else i for i in a]
    print(sum(a))
