#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Rmq
{
    int n;
    vector<int> data;
    int query(int a, int b, int k, int l, int r){
        if(r < a || b < l)
            return INT_MAX;
        if(a <= l && r <= b)
            return data[k];
        int x = query(a, b, k*2+1, l, (l+r)/2);
        int y = query(a, b, k*2+2, (l+r+1)/2, r);
        return min(x, y);
    }
public:
    Rmq(int n0){
        n = 1;
        while(n < n0)
            n *= 2;
        data.assign(2*n-1, INT_MAX);
    }
    Rmq(vector<int> vi){
        int n0 = vi.size();
        n = 1;
        while(n < n0)
            n *= 2;
        data.assign(2*n-1, INT_MAX);
        for(int i=0; i<n0; ++i)
            data[i+n-1] = vi[i];
        for(int i=n-2; i>=0; --i)
            data[i] = min(data[i*2+1], data[i*2+2]);
    }
    void update(int k, int a){
        k += n - 1;
        data[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            data[k] = min(data[k*2+1], data[k*2+2]);
        }
    }
    int query(int a, int b){
        return query(a, b, 0, 0, n-1);
    }
};

int main(){
    for(;;){
        int r, c, q;
        cin >> r >> c >> q;
        if(r == 0)
            return 0;

        if(r < c){
            vector<vector<int> > grid(r, vector<int>(c));
            for(int i=0; i<r; ++i){
                for(int j=0; j<c; ++j){
                    cin >> grid[i][j];
                }
            }
            vector<Rmq> rmq;
            for(int i=0; i<r; ++i)
                rmq.push_back(Rmq(grid[i]));

            for(int i=0; i<q; ++i){
                int r1, c1, r2, c2;
                cin >> r1 >> c1 >> r2 >> c2;
                int ret = INT_MAX;
                for(int i=r1; i<=r2; ++i)
                    ret = min(ret, rmq[i].query(c1, c2));
                cout << ret << endl;
            }
        }else{
            vector<vector<int> > grid(c, vector<int>(r));
            for(int i=0; i<r; ++i){
                for(int j=0; j<c; ++j){
                    cin >> grid[j][i];
                }
            }
            vector<Rmq> rmq;
            for(int i=0; i<c; ++i)
                rmq.push_back(Rmq(grid[i]));

            for(int i=0; i<q; ++i){
                int r1, c1, r2, c2;
                cin >> r1 >> c1 >> r2 >> c2;
                int ret = INT_MAX;
                for(int i=c1; i<=c2; ++i)
                    ret = min(ret, rmq[i].query(r1, r2));
                cout << ret << endl;
            }
        }
    }
}