#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;


int main(int argc, char* argv[]) {
    registerValidation(argc, argv);
    while (true) {
        int C = inf.readInt(0, 1000, "C");
        inf.readSpace();
        int R = inf.readInt(0, 1000, "R");
        inf.readEoln();
        if (C == 0 && R == 0) break;
        ensure(C != 0 || R != 0);

        int Cf, Rf, Ct, Rt;
        Cf = inf.readInt(1, C, "Cf");
        inf.readSpace();
        Rf = inf.readInt(1, R, "Rf");
        inf.readSpace();
        Ct = inf.readInt(1, C, "Ct");
        inf.readSpace();
        Rt = inf.readInt(1, R, "Rt");
        inf.readEoln();

        int W = inf.readInt(0, 1000, "W");
        inf.readEoln();

        for (int i = 0; i < W; i++) {
            int C1, C2, R1, R2;
            C1 = inf.readInt(1, C, "C1");
            inf.readSpace();
            R1 = inf.readInt(1, R, "R1");
            inf.readSpace();
            C2 = inf.readInt(1, C, "C2");
            inf.readSpace();
            R2 = inf.readInt(1, R, "R2");
            inf.readEoln();
            ensure(C1 <= C2);
            ensure(R1 <= R2);
        }

    }
    inf.readEof();
    return 0;
}