N = int(input())
A = sorted(list(map(int, input().split())))
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    if A[0] <= B <= A[-1]:
        for x in A:
            if x == B:
                x = C
        print(sum(A))
    else:
        print(sum(A))