Answering the second half of the question here, about figuring out how to get to Q4 and Q5 (and ignoring Q1 to Q6 for now)
The typical first naive way (also my initial way) of representing this as a state machine makes each question into its own state, with each state represented exactly once in the state machine. Using a statechart, you could extract the question 4 and 5 into a compound state in such a way that when Q4AND5 is active, exactly one of Q4 or Q5 are active:
<scxml>
<state id="Q1"/>
<state id="Q2"/>
<state id="Q3"/>
<state id="Q4AND5">
<state id="Q4"/>
<state id="Q5"/>
</state>
<state id="Q6"/>
</scxml>
Then transitions from Q3 to Q4AND5 would cause either Q4 or Q5 to become active, because of guarded transitions.
<scxml>
<state id="Q1">
<transition event="answer" target="Q2"/>
</state>
<state id="Q2">
<transition event="answer" target="Q3"/>
</state>
<state id="Q3">
<transition event="answer" target="Q4AND5"/>
</state>
<state id="Q4AND5">
<transition cond="if q1 == 'FOO' and q3 == 'BAR'" target="Q4"/>
<transition cond="if q1 == 'BAR' and q3 == 'FOO'" target="Q5"/>
<state id="Q4"/>
<state id="Q5"/>
<transition event="answer" target="Q6"/>
</state>
<state id="Q6"/>
</scxml>
Going back from Q6 would go to Q4AND5 which would cause the machine to enter either Q4 or Q5:
<state id="Q6">
<transition event="back" target="Q4AND5"/>
</state>
Now, after the question was modified to include Q1 to Q6 transition, it becomes apparent that modeling each question as a distinct state doesn't cut it. It's also not quite correct. If you think about it, there are two Q6 states, one after arriving at Q6 from Q1, and another after arriving at Q6 from Q4AND5. If we instead split those two Q6s into two distinct states, then it's quite easy to acommodate this new transition:
<scxml>
<state id="Q1">
<transition event="answer" target="Q6B" cond="q1 == 'BAZ'"/>
...
</state>
...
<state id="Q6A">
<transition event="back" target="Q4AND5"/>
</state>
<state id="Q6B">
<transition event="back" target="Q1"/>
</state>
</scxml>
The problem is now that Q6 is represented by two states (Q6A and Q6B). The solution here is to decouple from the names of the states themselves, and declare in each state which question to show, typically by way of an action or a change to some variable. Below I've define a data element that the statechart updates to the name of the correct question to show.
<scxml>
<datamodel>
<data id="question"> <!-- The name of the question to show -->
</datamodel>
<state id="Q1">
<assign location="question" expr="'Q1'"/>
<transition event="answer" target="Q6B" cond="q1 == 'BAZ'"/>
<transition event="answer" target="Q2"/>
</state>
<state id="Q2">
<assign location="question" expr="'Q2'"/>
<transition event="answer" target="Q3"/>
<transition event="back" target="Q1"/>
</state>
<state id="Q3">
<assign location="question" expr="'Q3'"/>
<transition event="answer" target="Q4AND5"/>
<transition event="back" target="Q2"/>
</state>
<state id="Q4AND5">
<transition event="answer" cond="if q1 == 'FOO' and q3 == 'BAR'" target="Q4"/>
<transition event="answer" cond="if q1 == 'BAR' and q3 == 'FOO'" target="Q5"/>
<transition event="back" target="Q3"/>
<state id="Q4">
<assign location="question" expr="'Q4'"/>
</state>
<state id="Q5">
<assign location="question" expr="'Q5'"/>
</state>
<transition event="answer" target="Q6A"/>
</state>
<state id="Q6A">
<assign location="question" expr="'Q6'"/>
<transition event="back" target="Q4AND5"/>
</state>
<state id="Q6B">
<assign location="question" expr="'Q6'"/>
<transition event="back" target="Q1"/>
</state>
</scxml>
This decoupling makes it easier to change the statechart, move things around without changing every user of the statechart. Conversely: depending on the state names outside the statechart/state machine causes the state names themselves to become the state machine's API, meaning it cannot be changed easily.