Module for a,b, and r: We compute the locally stratified model. There is just one stratum, and we are able to infer r(1,2) and r(2,3). The locally stratified model for this module is EDB + {r(1,2), r(2,3)}.
Module for q and p: We treat all true facts belonging
to the previous model as if they were EDB facts, and compute the
locally stratified model.
The modularly stratified model is EDB + {r(1,2), r(2,3), q(1), q(3), q(4), p(1)}.
Q2 is contained in Q1. Containment mapping from Q1 to Q2: U->U, Z->V, V->X, X->Y, Y->U.
Q2 is not contained in Q1. Choose constants X->0, Y->1, Z->2, U->3, V->4. The canonical database D for Q2 is {q(0,1), q(1,2), q(2,3), q(3,4)}, and p(0) is the frozen head of Q2. Q1(D) = {}. Q1(D) does not contain the frozen head of Q2.
Q3 is contained in Q2: X->X, A->A, B->c, C->B, Y->Y
Q3 is contained in Q4: X->X, A->A, C->c, B->A, E->B, D->B, Y->Y
Q2 is contained in Q4: X->X, A->A, C->B, B->A, E->C, D->C, Y->Y
Q4 is contained in Q2: X->X, A->A, B->C, C->E, Y->Y
None of Q2, Q3, and Q4 are contained in Q1, since for a containment mapping from Q1 to one of the other queries, the head would force X to map to both X and Y.
None of Q1, Q2, and Q4 are contained in Q3, since it would not be possible to map the third subgoal of Q3 (q(c,B)) to any subgoal in the other queries (the other queries don't have a subgoal of the form q(c,?)).
The canonical database D for Q1 is {q(0,1), q(1,2)}, with X->0, A->1, Z->2. The frozen head of Q1 is p(0,0). Q2(D) does not contain the frozen head of Q1, so Q1 is not contained in Q2. Similarly, Q4(D) does not contain the frozen head of Q1, so Q1 is not contained in Q4.