N=int(input())
A=list(map(int,input().split()))
Q=int(input())

trans=[[] for _ in range(Q)]
for i in range(Q):
    B,C=map(int,input().split())
    trans[i].append(B)
    trans[i].append(C)
    
for i in range(Q):
    B=trans[i][0]
    C=trans[i][1]
    A=[i if i != B else C for i in A]
    print(sum(A))
