import numpy as np
n = int(input())
a = np.array([int(k) for k in input().split()],dtype=np.uint64)
q = int(input())
for _ in range(q):
    b, c = [int(k) for k in input().split()]
    a[a == b] = c
    # print(a)
    print(np.sum(a))