#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=INT_MAX;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int Need(int x)
{
	x--;
	rep(i,5) x|=x>>(1<<i);
	return x+1;
}

struct SegmentTree{
	int size;
	vi data;
	SegmentTree(int s):size(Need(s)),data(size*2,INFTY){}
	SegmentTree(const vi& a):size(Need(a.size())),data(size*2,INFTY){
		copy(all(a),data.begin()+size);
		for(int i=size;--i;)
			data[i]=min(data[i*2],data[i*2+1]);
	}
	int Get(int i){
		return data[size+i];
	}
	void Update(int i,int x){
		data[size+i]=x;
		for(i=(i+size)/2;i;i/=2)
			data[i]=min(data[i*2],data[i*2+1]);
	}
	int Query(int a,int b,int i,int l,int r){
		if(b<=l || r<=a) return INFTY;
		if(a<=l && r<=b) return data[i];
		return min(Query(a,b,i*2,l,(l+r)/2),Query(a,b,i*2+1,(l+r)/2,r));
	}
	int Query(int a,int b){
		return Query(a,b,1,0,size);
	}
};

struct SegmentTree2D{
	int size;
	vector<SegmentTree> data;
	SegmentTree2D(int h,int w):size(Need(h)),data(size*2,SegmentTree(w)){}
	SegmentTree2D(const vvi& a):size(Need(a.size())),data(size*2,SegmentTree(a[0].size())){
		copy(all(a),data.begin()+size);
		for(int i=size;--i;)
			repi(j,1,data[i].data.size())
				data[i].data[j]=min(data[i*2].data[j],data[i*2+1].data[j]);
	}
	int Get(int i,int j){
		return data[size+i].Get(j);
	}
	void Update(int i,int j,int x){
		data[size+i].Update(j,x);
		for(i=(i+size)/2;i;i/=2)
			data[i].Update(j,min(data[i*2].Get(j),data[i*2+1].Get(j)));
	}
	int Query(int a,int b,int c,int d,int i,int to,int bo){
		if(c<=to || bo<=a) return INFTY;
		if(a<=to && bo<=c) return data[i].Query(b,d);
		return min(Query(a,b,c,d,i*2,to,(to+bo)/2),Query(a,b,c,d,i*2+1,(to+bo)/2,bo));
	}
	int Query(int a,int b,int c,int d){
		return Query(a,b,c,d,1,0,size);
	}
};

int main()
{
	for(int r,c,q;scanf("%d%d%d",&r,&c,&q),r|c|q;){
		vvi grid(min(r,c),vi(max(r,c)));
		if(r<=c) rep(i,r) rep(j,c) scanf("%d",&grid[i][j]);
		else     rep(j,r) rep(i,c) scanf("%d",&grid[i][j]);
		
		vi r1(q),c1(q),r2(q),c2(q);
		rep(i,q) scanf("%d%d%d%d",&r1[i],&c1[i],&r2[i],&c2[i]);
		
		if(r>c){
			swap(r,c);
			swap(r1,c1);
			swap(r2,c2);
		}
		
		SegmentTree2D st(grid);
		rep(i,q)
			printf("%d\n",st.Query(r1[i],c1[i],r2[i]+1,c2[i]+1));
	}
	
	return 0;
}

Measured memory_bytes: 39120