N = int(input())
a_list = list(map(int, input().split()))
Q = int(input())

r = [0] * (10**5)

for a in a_list:
    r[a-1] += a

for i in range(Q):
    b, c = map(int, input().split())
    tmp = r[b-1] // b
    r[b-1] = 0
    r[c-1] += tmp * c
    print(sum(r))