n = int(input())
A = sorted(list(map(int, input().split())))
q = int(input())

ans = sum(A)
for i in range(q):
    b, c = map(int, input().split())
    if b in A:
        pos = A.index(b)
        count = A.count(b)
        ans += ((c - b) * count)
        A = A[:pos] + [c] * count + A[pos + count:]
    print(ans)