n = int(input())
a = list(map(int,input().split()))
q = int(input())
u = []
for i in range(q):
    u.append(tuple(map(int,input().split())))

from collections import Counter
z = Counter(a)

sum = sum(a)
for i in range(q):
    try:
        rev = z.pop(u[i][0])
        sum+=(u[i][1]-u[i][0])*rev
        print(sum)
    except KeyError:
        print(sum)
    if u[i][1] in z.keys():
        z[u[i][1]]+=rev
    else:
        z[u[i][1]]=rev