#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <complex>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <deque>
#include <bitset>
#include <cctype>
#include <utility>
#include <cassert>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define SZ(S) ((int) ((S).size()))
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
const int MN = 1011;
const int oo = MN * MN;
const int MOD = 1000000007;
int n;
char a[MN][MN];
pair<int,int> f[MN][MN], g[MN][MN];
void update(pair<int,int> &f, pair<int,int> val, char c) {
int now = val.first + ((c == 'C') ? 1 : 0);
if (f.first < now) {
f.first = now;
f.second = val.second;
}
else if (f.first == now) {
f.second = (f.second + val.second) % MOD;
}
}
int main() {
ios :: sync_with_stdio(false); cin.tie(NULL);
cout << (fixed) << setprecision(6);
while (cin >> n) {
FOR(i,1,n) FOR(j,1,n) cin >> a[i][j];
FOR(i,0,n+1) FOR(j,0,n+1) f[i][j] = g[i][j] = make_pair(-oo, 0);
FOR(i,1,n) FOR(j,1,n) {
if (i == 1 && j == 1) {
if (a[i][j] == 'C') f[i][j] = make_pair(1, 1);
else f[i][j] = make_pair(0, 1);
}
else {
update(f[i][j], f[i-1][j], a[i][j]);
update(f[i][j], f[i][j-1], a[i][j]);
}
}
FORD(i,n,1) FORD(j,n,1) {
if (i == n && j == n) {
if (a[i][j] == 'C') g[i][j] = make_pair(1, 1);
else g[i][j] = make_pair(0, 1);
}
else {
update(g[i][j], g[i+1][j], a[i][j]);
update(g[i][j], g[i][j+1], a[i][j]);
}
}
int q; cin >> q;
while (q--) {
int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
++r1; ++c1; ++r2; ++c2;
if (r1 > r2) swap(r1, r2);
if (c1 > c2) swap(c1, c2);
pair<int,int> res = make_pair(0, 0);
FOR(i,r2+1,n) {
pair<int,int> cur = make_pair(f[i][c1-1].first + g[i][c1].first,
f[i][c1-1].second * (long long) g[i][c1].second % MOD);
update(res, cur, 0);
}
FOR(j,c2+1,n) {
pair<int,int> cur = make_pair(f[r1-1][j].first + g[r1][j].first,
f[r1-1][j].second * (long long) g[r1][j].second % MOD);
update(res, cur, 0);
}
cout << res.first << ' ' << res.second << "\n";
}
}
return 0;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8Y29tcGxleD4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxjY3R5cGU+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8Y2Fzc2VydD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgRk9SKGksYSxiKSBmb3IoaW50IGk9KGEpLF9iPShiKTsgaTw9X2I7IGkrKykK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Yuc2Vjb25kICsgdmFsLnNlY29uZCkgJSBNT0Q7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgaW9zIDo6IHN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoTlVMTCk7CiAgICBjb3V0IDw8IChmaXhlZCkgPDwgc2V0cHJlY2lzaW9uKDYpOwogICAgd2hpbGUgKGNpbiA+PiBuKSB7CiAgICAgICAgRk9SKGksMSxuKSBGT1IoaiwxLG4pIGNpbiA+PiBhW2ldW2pdOwogICAgICAgIEZPUihpLDAsbisxKSBGT1IoaiwwLG4rMSkgZltpXVtqXSA9IGdbaV1bal0gPSBtYWtlX3BhaXIoLW9vLCAwKTsKCiAgICAgICAgRk9SKGksMSxuKSBGT1IoaiwxLG4pIHsKICAgICAgICAgICAgaWYgKGkgPT0gMSAmJiBqID09IDEpIHsKICAgICAgICAgICAgICAgIGlmIChhW2ldW2pdID09ICdDJykgZltpXVtqXSA9IG1ha2VfcGFpcigxLCAxKTsKICAgICAgICAgICAgICAgIGVsc2UgZltpXVtqXSA9IG1ha2VfcGFpcigwLCAxKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgIHVwZGF0ZShmW2ldW2pdLCBmW2ktMV1bal0sIGFbaV1bal0pOwogICAgICAgICAgICAgICAgdXBkYXRlKGZbaV1bal0sIGZbaV1bai0xXSwgYVtpXVtqXSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgRk9SRChpLG4sMSkgRk9SRChqLG4sMSkgewogICAgICAgICAgICBpZiAoaSA9PSBuICYmIGogPT0gbikgewogICAgICAgICAgICAgICAgaWYgKGFbaV1bal0gPT0gJ0MnKSBnW2ldW2pdID0gbWFrZV9wYWlyKDEsIDEpOwogICAgICAgICAgICAgICAgZWxzZSBnW2ldW2pdID0gbWFrZV9wYWlyKDAsIDEpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgdXBkYXRlKGdbaV1bal0sIGdbaSsxXVtqXSwgYVtpXVtqXSk7CiAgICAgICAgICAgICAgICB1cGRhdGUoZ1tpXVtqXSwgZ1tpXVtqKzFdLCBhW2ldW2pdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaW50IHE7IGNpbiA+PiBxOwogICAgICAgIHdoaWxlIChxLS0pIHsKICAgICAgICAgICAgaW50IHIxLCBjMSwgcjIsIGMyOyBjaW4gPj4gcjEgPj4gYzEgPj4gcjIgPj4gYzI7CiAgICAgICAgICAgICsrcjE7ICsrYzE7ICsrcjI7ICsrYzI7CgogICAgICAgICAgICBpZiAocjEgPiByMikgc3dhcChyMSwgcjIpOwogICAgICAgICAgICBpZiAoYzEgPiBjMikgc3dhcChjMSwgYzIpOwoKICAgICAgICAgICAgcGFpcjxpbnQsaW50PiByZXMgPSBtYWtlX3BhaXIoMCwgMCk7CiAgICAgICAgICAgIEZPUihpLHIyKzEsbikgewogICAgICAgICAgICAgICAgcGFpcjxpbnQsaW50PiBjdXIgPSBtYWtlX3BhaXIoZltpXVtjMS0xXS5maXJzdCArIGdbaV1bYzFdLmZpcnN0LAogICAgICAgICAgICAgICAgICAgICAgICBmW2ldW2MxLTFdLnNlY29uZCAqIChsb25nIGxvbmcpIGdbaV1bYzFdLnNlY29uZCAlIE1PRCk7CiAgICAgICAgICAgICAgICB1cGRhdGUocmVzLCBjdXIsIDApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIEZPUihqLGMyKzEsbikgewogICAgICAgICAgICAgICAgcGFpcjxpbnQsaW50PiBjdXIgPSBtYWtlX3BhaXIoZltyMS0xXVtqXS5maXJzdCArIGdbcjFdW2pdLmZpcnN0LAogICAgICAgICAgICAgICAgICAgICAgICBmW3IxLTFdW2pdLnNlY29uZCAqIChsb25nIGxvbmcpIGdbcjFdW2pdLnNlY29uZCAlIE1PRCk7CiAgICAgICAgICAgICAgICB1cGRhdGUocmVzLCBjdXIsIDApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvdXQgPDwgcmVzLmZpcnN0IDw8ICcgJyA8PCByZXMuc2Vjb25kIDw8ICJcbiI7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0KCg==