import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
for _ in [0]*Q:
    b, c = map(int, input().split())
    A[A==b] = c
    print(A)
    print(np.sum(A))