n=int(input())
l=list(map(int, input().split()))
q=int(input())
for i in range(q):
    z=0
    a, b=map(int, input().split())
    for j in range (n):
        if l[j]==a:
            l[j]=b
    for i in range (n):
        z+=l[i]
    print(z)
