B = list()
C = list()
D = list()
int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    bb, cc= map(int, input().split()) 
    A = [cc if k == bb else k for k in A]
    D.append(sum(A))
for i in range(3):
    print(D[i])