a=int(input())
b=list(map(int,input().split()))
c=int(input())
d=[list(map(int,input().split())) for i in range(c)]
for i in range(c):
    for j in range(a):
        if b[j]==d[i][0]:
            b[j]=d[i][1]
    print(sum(b))