#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 5;
const int M = 3e5 + 5;
int n, m, q;
char c[N][N];
int sum[5][N][N];
int ans[M];
int r1[M], c1[M], r2[M], c2[M];
void init(int id, char x) {
  for (int i = (1); i < (n + 1); i++) {
    for (int j = (1); j < (m + 1); j++) {
      sum[id][i][j] =
          sum[id][i - 1][j] + sum[id][i][j - 1] - sum[id][i - 1][j - 1];
      if (c[i][j] == x) sum[id][i][j]++;
    }
  }
}
vector<pair<long long, int> > g[N];
int get(int id, int x, int y, int len) {
  int x1, y1, x2, y2;
  x1 = x, y1 = y, x2 = x + len - 1, y2 = y + len - 1;
  return sum[id][x2][y2] - sum[id][x1 - 1][y2] - sum[id][x2][y1 - 1] +
         sum[id][x1 - 1][y1 - 1];
}
void solve(int x, int y) {
  for (int len = (1); len < (500 + 1); len++) {
    if (n - x + 1 < len * 2 || m - y + 1 < len * 2) return;
    int t;
    t = get(0, x, y, len * 2);
    if (get(0, x, y, len) != t || t != len * len) continue;
    t = get(1, x, y, len * 2);
    if (get(1, x, y + len, len) != t || t != len * len) continue;
    t = get(2, x, y, len * 2);
    if (get(2, x + len, y, len) != t || t != len * len) continue;
    t = get(3, x, y, len * 2);
    if (get(3, x + len, y + len, len) != t || t != len * len) continue;
    g[len].push_back(pair<long long, int>(x, y));
  }
}
int ss[N][N];
void init1(int len) {
  for (int i = (0); i < (n + 1); i++)
    for (int j = (0); j < (m + 1); j++) ss[i][j] = 0;
  for (auto it : g[len]) ss[it.first][it.second]++;
  for (int i = (1); i < (n + 1); i++)
    for (int j = (1); j < (m + 1); j++)
      ss[i][j] += ss[i - 1][j] + ss[i][j - 1] - ss[i - 1][j - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  for (int i = (1); i < (n + 1); i++) cin >> (c[i] + 1);
  init(0, 'R');
  init(1, 'G');
  init(2, 'Y');
  init(3, 'B');
  for (int i = (1); i < (n + 1); i++)
    for (int j = (1); j < (m + 1); j++) solve(i, j);
  for (int i = (1); i < (q + 1); i++) cin >> r1[i] >> c1[i] >> r2[i] >> c2[i];
  for (int len = (1); len < (min(n, m) / 2 + 1); len++) {
    init1(len);
    for (int i = (1); i < (q + 1); i++) {
      int x1 = r1[i], y1 = c1[i], x2 = r2[i] - len * 2 + 1,
          y2 = c2[i] - len * 2 + 1;
      if (x1 > x2 || y1 > y2) continue;
      int now =
          ss[x2][y2] - ss[x1 - 1][y2] - ss[x2][y1 - 1] + ss[x1 - 1][y1 - 1];
      if (now) ans[i] = len;
    }
  }
  for (int i = (1); i < (q + 1); i++) {
    cout << ans[i] * ans[i] * 4 << "\n";
  }
  return 0;
}
