N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B_C = [list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    newlist = B_C[i]
    c = newlist[1]
    b = newlist[0]
    A = [c if k == b else k for k in A]
    print(sum(A))