n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int,input().split())) for i in range(q)]
l1 = []
l2 = []
ans = sum(a)
for i in range(q):
    b = bc[i][0]
    c = bc[i][1]
    cnt = a.count(b)
    cnt2 = cnt + l2.count(b) - l1.count(b)
    for j in range(cnt):
        l1.append(b)
        l2.append(c)
    dif = c - b
    ans += dif * cnt2
    print(ans)