# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

for i in range(Q):
    b,c=map(int,input().split())
    for j in range(N):
        if A[j]==b:
            A[j]=c
        else:
            pass
    print(sum(A))
