n = int(input())
a = list(map(int,input().split()))
ans = sum(a)
#print(ans)
q = int(input())
b = []
c = []
from itertools import groupby
d = [[key,len(list(group))] for key,group in groupby(sorted(a))]

for j in range(q):
    b,c = map(int,input().split())
    
    for i in range(len(d)):
        if b==d[i][0]:
            d[i][0] = c
            ans = ans + ((c-b)*d[i][1])
    print(ans)