n=int(input())
a=list(map(int,input().split()))
q=int(input())
lista=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
    for j in range(len(a)):
        if a[j]==lista[i][0]:
            a[j]=lista[i][1]
    print(sum(a))
