import numpy as np
n = input()
a = np.array([*map(int, input().split())])
q = int(input())
b = [[*map(int,input().split())] for _ in range(q)]
for i,j in b:
    a = np.where(a==i, j, a)
    print(sum(a))