
if __name__=="__main__":
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    bc = [list(map(int, input().split())) for l in range(Q)]
#    print(bc)

    for i in range(0,Q):
        tmp = bc[i][0]
#        print(tmp)
        for j in range(N):
            if A[j] == tmp:
                A[j] = bc[i][1]
        total = sum(A)
        print(total)

