import collections
N = int(input())
A = list(map(int,input().split()))
D = collections.Counter(A)
Q = int(input())
#print(D)
ans = sum(A)
for i in range(Q):
    B,C = map(int,input().split())
    #print(D[B],type(D[B]))
    ans += (C-B)*D[B]
    print(ans)