N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
for i in range(Q):
    BC = [int(x) for x in input().split()]
    B = BC[0]
    C = BC[1]
    A = [C if k == B else k for k in A]
    print(sum(A))