#include<bits/stdc++.h>
#define MAXN 2007
#define MAXK 1000007
using namespace std;

struct carpet{ int a,b,c,d; }carp[MAXK];

int n,m,k;
int cover[MAXN][MAXN];
int pref[MAXN][MAXN];
int bit[MAXN][MAXN];  


void fen_add(int r, int c, int v){
    for(; c<=m; c+=c&(-c)) bit[r][c]+=v;
}

int fen_sum(int r, int c){    
    int s=0;
    for(; c>0; c-=c&(-c)) s+=bit[r][c];
    return s;
}

int fen_kth(int r, int k){
    int pos=0;
    for(int pw=11; pw>=0; pw--){  
        int npos=pos+(1<<pw);
        if(npos<=m && bit[r][npos]<k){
            pos=npos;
            k-=bit[r][pos];
        }
    }
    return pos+1;
}

int firstcol_fen(int r, int ca, int cb){
    int before=fen_sum(r, ca-1);
    if(fen_sum(r, cb)==before) return cb+1;   
    return fen_kth(r, before+1);         
}

int sum2d(int r1, int r2, int c1, int c2){
    return pref[r2][c2]-pref[r2][c1-1]-pref[r1-1][c2]+pref[r1-1][c1-1];
}

int firstrow(int ra, int rb, int ca, int cb){
    int lt=ra-1, rt=rb+1, tt;
    while(lt+1<rt){
        tt=(lt+rt)/2;
        if(sum2d(ra,tt,ca,cb)>0) rt=tt;
        else                      lt=tt;
    }
    return rt;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin>>n>>m>>k;
    for(int i=1;i<=k;i++){
        int a,b,c,d; cin>>a>>b>>c>>d;
        carp[i]={a,b,c,d};
        cover[a][c]++;
        cover[a][d+1]--;
        cover[b+1][c]--;
        cover[b+1][d+1]++;
    }

    for(int r=1;r<=n;r++){
        for(int c=1;c<=m;c++){
            cover[r][c]+=cover[r-1][c]+cover[r][c-1]-cover[r-1][c-1];

            int excl=(cover[r][c]==1) ? 1 : 0;
            pref[r][c]=excl+pref[r-1][c]+pref[r][c-1]-pref[r-1][c-1];
            if(excl) fen_add(r, c, 1);
        }
    }

    for(int i=1;i<=k;i++){
        int ra=carp[i].a, rb=carp[i].b, ca=carp[i].c, cb=carp[i].d;
        vector<pair<int,int>> res;

        int row=ra-1;
        while(true){
            row=firstrow(row+1, rb, ca, cb);
            if(row==rb+1) break;

            int col=ca-1;
            while(true){
                col=firstcol_fen(row, col+1, cb);
                if(col==cb+1) break;
                res.push_back({row,col});
            }
        }

        cout<<res.size()<<" : ";
        for(auto [x,y]:res) cout<<"("<<x<<","<<y<<") ";
        cout<<"\n";
    }

    return 0;
}
