public function recode_legacy_state_answer($state) {
        global $DB;
        $answer = $state->answer;
        $resultarr = array();
        // Get sequence of questions.
        $sequence = $DB->get_field('question_multianswer', 'sequence',
                array('question' => $state->question));
        $sequencearr = explode(',', $sequence);
        // Let's process each pair.
        foreach (explode(',', $answer) as $pair) {
            $pairarr = explode('-', $pair);
            $sequenceid = $pairarr[0];
            $subanswer = $pairarr[1];
            // Calculate the questionid based on sequenceid.
            // Note it is already one *new* questionid that doesn't need mapping.
            $questionid = $sequencearr[$sequenceid - 1];
            // Fetch qtype of the question (needed for delegation).
            $questionqtype = $DB->get_field('question', 'qtype', array('id' => $questionid));
            // Delegate subanswer recode to proper qtype, faking one question_states record.
            $substate = new stdClass();
            $substate->question = $questionid;
            $substate->answer = $subanswer;
            $newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
            $resultarr[] = implode('-', array($sequenceid, $newanswer));
        }
        return implode(',', $resultarr);
    }