#include<stdio.h>
#include<string.h>
typedef struct treetype{
	long l,r,ll,rr,min;
}treetype;
treetype tree[3000005];
long r,c,q,i,j,c1,c2,r1,r2,ans,top,dd;
bool ok;
long a[1000005];
long start[1000005];
long min(long a,long b){
	return a<b?a:b;
}
void maketree(long i,long l,long r)
{
  long mid,lson,rson;
  tree[i].l=l;tree[i].r=r;
  tree[i].min=0;
  if (l==r){
  	  tree[i].min=a[dd];
  	  dd++;
		return;
  }
  mid=(l+r)/2;
  top++;
  tree[i].ll=lson=top;
  maketree(top,l,mid);
  top++;
  tree[i].rr=rson=top;
  maketree(top,mid+1,r);
	tree[i].min=min(tree[lson].min,tree[rson].min);  
}
long count(long i,long a,long b){
	long lson,rson,l,r,mid;
	lson=tree[i].ll;rson=tree[i].rr;l=tree[i].l;r=tree[i].r;
	if (l==a && r==b)
	  return tree[i].min;
  mid=(l+r)/2;
  if (a>mid)
    return count(rson,a,b);
  else if (b<=mid)
    return count(lson,a,b);
  else
    return min(count(lson,a,mid),count(rson,mid+1,b));
}
int main(){
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	while (scanf("%ld %ld %ld",&r,&c,&q)==3){
		if (r==0)
		  return 0;
		memset(tree,0,sizeof(tree));
		memset(start,0,sizeof(start));
		memset(a,0,sizeof(a));
		if (r<=c){
		  for (i=0;i<r;i++)
		    for (j=0;j<c;j++)
		      scanf("%ld",&a[i*c+j]);
		}
		else if (r>c){
			for (i=0;i<r;i++)
			  for (j=0;j<c;j++)
			    scanf("%ld",&a[j*r+i]);
		}
		top=0;ok=false;
		if (r>c){
			int temp=r;r=c;c=temp;
			ok=true;
		}
		dd=0;
		for (i=0;i<r;i++){
			top++;
 	    start[i]=top;
		  maketree(top,0,c-1);
		}
		for (i=0;i<q;i++){
			scanf("%ld %ld %ld %ld",&r1,&c1,&r2,&c2);
			if (ok){
				int temp=r1;
				r1=c1;
				c1=temp;
				temp=r2;
				r2=c2;
				c2=temp;
			}
			ans=2147483647;
			for (j=r1;j<=r2;j++)
		    ans=min(ans,count(start[j],c1,c2));
      printf("%ld\n",ans);
		}
	}
}