import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
q = int(input())
oper = [list(map(int, input().split())) for _ in range(q)]
a.sort()
res = sum(a)

for i in range(q):
    b, c = oper[i]
    if b in a:
        bCount = a.count(b)
        idx = a.index(b)

        a = a[:idx] + a[idx+1:]
        a.extend([c]*bCount)
        dif = c-b

        res += dif*bCount

    print(res)