n=int(input())
l1=list(map(int,input().split()))
q=int(input())
for _ in range(q):
    a,b=map(int,input().split())
    for i in range(n):
        if l1[i]==a:
            l1[i]=b
    p=sum(l1)
    k=p
    print(k)