#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
using namespace std;
typedef pair<int,int> P;
int n,rnk[101];
P p[100];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		p[i].first=0;
		p[i].second=i+1;
	}
	for(int i=0;i<n*(n-1)/2;i++){
		int a,b,c,d;cin>>a>>b>>c>>d;a--;b--;
		if(c!=d){
			p[c>d?a:b].first+=3;
		}else{
			p[a].first+=1;
			p[b].first+=1;
		}
	}
	sort(p,p+n,greater<P>());
	for(int i=1;i<=n;i++){
		int r=i;
		if(i!=1&&p[i-1].first==p[i-2].first)r=rnk[p[i-2].second];
		rnk[p[i-1].second]=r;
	}
	for(int i=1;i<=n;i++){
		cout<<rnk[i]<<endl;
	}
}
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;

const int maxn = 2005;
int v[maxn][maxn], e0[maxn][maxn], e1[maxn][maxn];
int n, m, Q, X1, X2, Y1, Y2;
char s[maxn];

int main() {
	scanf("%d%d%d", &n, &m, &Q);
	rep (i, 1, n) {
		scanf("%s", s + 1);
		rep (j, 1, m)
			v[i][j] = s[j] - '0';
	}
	rep (i, 1, n) rep (j, 1, m) if (v[i][j]) {
		if (v[i-1][j]) e0[i][j]++;
		if (v[i][j-1]) e1[i][j]++;
	}
	rep (i, 1, n) rep (j, 1, m) {
		v[i][j] += v[i-1][j] + v[i][j-1] - v[i-1][j-1];
		e0[i][j] += e0[i-1][j] + e0[i][j-1] - e0[i-1][j-1];
		e1[i][j] += e1[i-1][j] + e1[i][j-1] - e1[i-1][j-1];
	}
	while (Q--) {
		scanf("%d%d%d%d", &X1, &Y1, &X2, &Y2);
		printf("%d\n", 
			v[X2][Y2] - v[X1-1][Y2] - v[X2][Y1-1] + v[X1-1][Y1-1]
		 - (e0[X2][Y2] - e0[X1][Y2] - e0[X2][Y1-1] + e0[X1][Y1-1])
		 - (e1[X2][Y2] - e1[X1-1][Y2] - e1[X2][Y1] + e1[X1-1][Y1])
		);
	}
	return 0;
}