IN A
IN B
MOV G 0
MOV H 1

; --- QUERY LOOP ---
CMP B G
JNZ 45
SUB B H
IN C
IN D
IN E

; --- BRANCH ---
CMP C H
JZ 30

; --- QUERY TYPE 1 ---
IN F
CMP D E
JZ 7
LOAD D A
ADD A F
STORE D A
ADD D H
CMP H G
JZ 20

; --- QUERY TYPE 2 ---
MOV F 0
CMP D E
JZ 40
LOAD D A
ADD F A
ADD D H
CMP H G
JZ 31

; --- OUTPUT RESULT ---
OUT F
CMP H G
JZ 7

; --- TERMINATE ---
RETURN

; A - N
; B - Q
; C - T
; D - L
; E - R
; F - X