#N = int(input())
#A = list(map(int, input().split()))
#a, b = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    A = [c if i == b else i for i in A]
    print(sum(A))