import sys
import numpy as np 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(input())
a = list(map(int, input().split()))
'''
aa = ''.join(a)
aaa = str(aa)
#print(type(aa))
# print(a)
'''
aa = np.array(a)
q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    aa = np.where(aa == b, c, aa) 
    print(np.sum(aa))
    #aaa.replace(str(b), str(c))
    #print(aaa)

#ab = map(int, aa)
#print(np.sum(aa))
