
n=int(input())
p=list(map(int,input().split()))
q=int(input())

for i in range(q):
    b,c=map(int,input().split())
    for j in range(len(p)):
        if p[j]==b:
            p[j]=c
    print(sum(p))