// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 123456789
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
long long mod =1000000007;
vector<string> V(N);
for(int i =0; i < N; i++) cin >> V[i];
vector< vector< pair<int,long long> > > A(N+2,vector<pair<int,long long> >(N+2,make_pair(0,0)));
A[1][1] =make_pair((int)(V[0][0] == 'C'),1);
for(int i =1; i <= N; i++) for(int j =1; j <= N; j++) if(i != 1 || j != 1) {
pair<int,long long> p1 =A[i-1][j], p2 =A[i][j-1];
if(p1.ff < p2.ff) swap(p1,p2);
if(p1.ff == p2.ff) p1.ss +=p2.ss;
if(p1.ss >= mod) p1.ss -=mod;
p1.ff +=(int)(V[i-1][j-1] == 'C');
A[i][j] =p1;}
vector< vector< pair<int,long long> > > B(N+2,vector<pair<int,long long> >(N+2,make_pair(0,0)));
B[N][N] =make_pair((int)(V[N-1][N-1] == 'C'),1);
for(int i =N; i > 0; i--) for(int j =N; j > 0; j--) if(i < N || j < N) {
pair<int,long long> p1 =B[i+1][j], p2 =B[i][j+1];
if(p1.ff < p2.ff) swap(p1,p2);
if(p1.ff == p2.ff) p1.ss +=p2.ss;
if(p1.ss >= mod) p1.ss -=mod;
p1.ff +=(int)(V[i-1][j-1] == 'C');
B[i][j] =p1;}
int Q;
cin >> Q;
for(int q =0; q < Q; q++) {
int r1,r2,c1,c2;
cin >> r1 >> c1 >> r2 >> c2;
pair<int,long long> p =make_pair(0,0);
for(int i =r2+2; i <= N; i++) {
pair<int,long long> p1 =A[i][c1], p2 =B[i][c1+1];
p1.ff +=p2.ff;
p1.ss =(p1.ss*p2.ss)%mod;
if(p1.ss < 0) p1.ss +=mod;
if(p1.ss == 0) p1.ff =0;
if(p1.ff > p.ff) {
p.ff =p1.ff;
p.ss =0;}
if(p1.ff == p.ff) p.ss +=p1.ss;
if(p.ss >= mod) p.ss -=mod;}
for(int j =c2+2; j <= N; j++) {
pair<int,long long> p1 =A[r1][j], p2 =B[r1+1][j];
p1.ff +=p2.ff;
p1.ss =(p1.ss*p2.ss)%mod;
if(p1.ss < 0) p1.ss +=mod;
if(p1.ss == 0) p1.ff =0;
if(p1.ff > p.ff) {
p.ff =p1.ff;
p.ss =0;}
if(p1.ff == p.ff) p.ss +=p1.ss;
if(p.ss >= mod) p.ss -=mod;}
if(p.ss == 0) p.ff =0;
cout << p.ff << " " << p.ss << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9tYW5pcD4KI2RlZmluZSBkaWJzIHJlc2VydmUKI2RlZmluZSBPVkVSOTAwMCAxMjM0NTY3ODkKI2RlZmluZSBBTExfVEhFKENBS0UsTElFKSBmb3IoYXV0byBMSUUgPUNBS0UuYmVnaW4oKTsgTElFICE9IENBS0UuZW5kKCk7IExJRSsrKQojZGVmaW5lIHRpc2ljIDQ3CiNkZWZpbmUgc29jbG9zZS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