N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
from collections import defaultdict
cntr = defaultdict(int)
for a in A:
    cntr[a] += 1
keys = [x for x in range(10**5+1)]
mp = dict([(x,[x]) for x in range(10**5+1)])
for b, c in Query:
    mp[c].append(b)
    for k in mp[b]:
        keys[k] = c
    ans = 0
    for k, v in cntr.items():
        ans += keys[k] * v
    print(ans)