# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B = []
C = []
for _ in range(Q):
    B_i, C_i = list(map(int, input().split()))
    
    B.append(B_i)
    C.append(C_i)

for i in range(Q):
    A = [A[j] if A[j] != B[i] else C[i] for j in range(len(A))]
    print(sum(A))
