import numpy as np
n = int(input())
a = np.array([int(k) for k in input().split()],dtype=np.uint64)
q = int(input())
r = int(np.sum(a))
for _ in range(q):
    b, c = [int(k) for k in input().split()]
    d = a == b
    s = len(a[d])
    a[d] = c
    r += (c - b) * s
    print(r)