import numpy as np
N = int(input())
seq = list(map(int,input().split()))
np_seq = np.array(seq)
Q = int(input())
for i in range(Q):
    bi, ci = map(int,input().split())
    np_seq = np.where(np_seq==bi,ci,np_seq)
    print(np_seq.sum())