#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF INT_MAX
typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}
 
vector< vector<int> > one , two;
 
void put(vector<int> &s,int x,int v){
    x += s.size()/2-1;
    while(x){
        s[x] = min(v,s[x]);
        x /= 2;
    }
}
int get(vector<int> &s,int l,int r,int k,int a,int b){
    //cout << a << " " << b << " " << s.size() << " " << endl;
    if(l==a && r==b) return s[k];
    if(b < l || r < a) return INF;
    return min(get(s,l,min((a+b)/2,r),k*2,a,(a+b)/2),get(s,max((a+b+1)/2,l),r,k*2+1,(a+b+1)/2,b));
}
 
int gen(int n){
    int ans = 1;
    while(ans < n) ans *= 2;
    return ans;
}
 
int main(){
    int H,W,Q;
    while(H = in() , W = in() , Q = in() , H){
        one.resize(H+1);
        two.resize(W+1);
        int hH = gen(H) , wW = gen(W);
        for(int i = 1 ; i <= H ; i++){
            one[i].resize(2*wW+1);
            fill(one[i].begin(),one[i].end(),INF);
        }
        for(int i = 1 ; i <= W ; i++){
            two[i].resize(2*hH+1);
            fill(two[i].begin(),two[i].end(),INF);
        }
        for(int i = 1 ; i <= H ; i++)
            for(int j = 1 ; j <= W ; j++){
                int a; a = in();
                put(one[i],j,a);
                put(two[j],i,a);
            }
        for(int i = 0 ; i < Q ; i++){
            int y1 = in() , x1 = in() , y2 = in() , x2 = in();
            x1++,y1++,x2++,y2++;
            if(x2-x1 >= y2-y1){
                int ans = INT_MAX;
                for(int j = y1 ; j <= y2 ; ++j) ans = min( ans , get(one[j],x1,x2,1,1,wW) );
                printf("%d\n",ans);
            }else{
                int ans = INT_MAX;
                for(int j = x1 ; j <= x2 ; ++j) ans = min( ans , get(two[j],y1,y2,1,1,hH) );
                printf("%d\n",ans);
            }
        }
         
    }
}