import collections
def change_dict_key_exist_setdefault(d, old_key, new_key):
    if old_key in d:
        tmp = d[new_key]
        d.setdefault(new_key, d.pop(old_key))
        d[new_key] += tmp
        #print(d)
N = int(input())
A_li = list(map(int,input().split()))
ans = sum(A_li)
c = collections.Counter(A_li)
#print(c)
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    ans -= c[B] * (B-C)
    print(ans)
    change_dict_key_exist_setdefault(c,B,C)
