import numpy as np
N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())

A = np.array(A)
l = A
for i in range(Q):
    B, C = map(int, input().split())
    A[A==B]=C
    l = np.vstack((l,A))

s = np.sum(l, axis=1)
s = s.tolist()
for j in range(Q):
    print(s[j+1])