import sys
input = sys.stdin.readline
N = int(input())
A = sorted(int(x) for x in input().split())
Q = int(input())
for _ in range(Q):
    BC = input().split()
    B, C = int(BC[0]), int(BC[1])
    A = [C if i == B else i for i in A]
    print(sum(A))