import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N=int(input())
A_row=LI()
Q=int(input())
B_C=[LI() for _ in range(Q)]

for i in range(Q):
    for j in range(N):
        if A_row[j]==B_C[i][0]:
            A_row[j]=B_C[i][1]
    print(sum(A_row))