N = int(input())
A = input().split()
A = [int(s) for s in A]



num = int(input())
for i in range(num):
    B, C = map(int, input().split())
    A.sort()
    for j in range(N):
        if A[j] == B:
            A[j] = C
        elif A[j] > B:
            break
    print(sum(A))