n=int(input())
a=list(map(int,input().split(' ')))
q=int(input())
for _ in range(q):
    s=0
    b,c = map(int,input().split(' '))
    a=[c if x==b else x for x in a]
    for i in a:
        s+=i
    print(s)






