To get the best final result, I suggest the following:

First, let’s think together about improving your structure. Because it is the improvement of the structure that gives a qualitative and longterm effect in the work. The work with logic is simplified, the tasks of scaling in the future are simplified, and the work becomes more stable and flexible. The structure I proposed above can work not only with binary questions. The proposed structure can serve any questions and even a unique questionnaire (when each user has unique questions that differ from the questions of other users). If, after all, the proposed structure cannot serve some specific task, tell us more about this task, we will try to optimize the structure for it.

If, after all, the problem can not be solved by optimizing the structure of data tables. Let’s move on to the solution at the logic level. We will try to find a solution based on your table structure.