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(len(b)):
    for j in range(len(a)):
        if a[j]==b[i]:
            a[j]=c[i]
    

    print(sum(a))