import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    a, b = map(int, input().split())
    B.append(a)
    C.append(b)
d = collections.Counter(A)
ans = 0
c = list(d.keys())
cs = list(d.values())
for i in range(Q):
    l=[j for j,x in enumerate(c) if x == B[i]]

    for k in l:
        c[k]=C[i]
    for m in range(len(c)):
        ans += c[m]*cs[m]
    print(ans)
    ans = 0
