# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_np =np.array(A,dtype=np.int64)
Q = int(input())
S =[0]*Q
for i in range(Q):
    b,c = (int(i) for i in input().split())
    A_np =np.where(A_np ==b,c,A_np)
    S[i] =np.sum(A_np)
    print(A_np)


print(*S,sep='\n')