Bethe ansatz for quantum strings