# coding: utf-8
# Your code here!
N=input()
AList = list(map(int, input().split()))
Q=int(input())
BCList=[list(map(int, input().split())) for i in range(Q)]

for i in range(Q):
    for j in range(len(AList)):
        if AList[j]==BCList[i][0]:
            AList[j]=BCList[i][1]
        
    print(sum(AList))