import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
    B, C = list(map(int, input().split()))
    A = [C if i == B else i for i in A]
    print(sum(A))