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