n=int(input())
l=list(map(int,input().split()))
q=int(input())
l1=[]
for i in range(q):
    b,c=map(int,input().split())
    for j in range(n):
        if l[j]==b:
            l[j]=c
    l1.append(sum(l))
for k in l1:
    print(k)
