b=[]
c=[]
n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)
for i in range(q):
    for j in range(n):
        if(a[j]==b[i]):
            a[j]=c[i]
    sum=0
    for i in range(n):
        sum+=a[i]
    print(sum)