#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int P = 1000000007;
const int V = 510;
const int QN = 300100;
char mp[V][V];
int id(char c) {
  if (c == 'R') return 0;
  if (c == 'G') return 1;
  if (c == 'Y')
    return 2;
  else
    return 3;
}
int s[V][V][4];
int ts[V][V];
int cal(int sx, int sy, int ex, int ey, int c) {
  if (sx > ex) return 0;
  if (sy > ey) return 0;
  return s[ex][ey][c] - s[ex][sy][c] - s[sx][ey][c] + s[sx][sy][c];
}
int cal2(int sx, int sy, int ex, int ey) {
  if (sx > ex) return 0;
  if (sy > ey) return 0;
  return ts[ex][ey] - ts[ex][sy] - ts[sx][ey] + ts[sx][sy];
}
int ans[QN];
int sx[QN], sy[QN], ex[QN], ey[QN];
int n, m, Q;
int main() {
  while (~scanf("%d%d%d", &n, &m, &Q)) {
    for (int i = 0; i < n; ++i) scanf("%s", mp[i]);
    for (int i = 0; i < Q; ++i) {
      scanf("%d%d%d%d", &sx[i], &sy[i], &ex[i], &ey[i]);
    }
    memset(s, 0, sizeof(s));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        for (int k = 0; k < 4; ++k) s[i + 1][j + 1][k] = s[i + 1][j][k];
        s[i + 1][j + 1][id(mp[i][j])]++;
      }
      for (int j = 1; j <= m; ++j)
        for (int k = 0; k < 4; ++k) s[i + 1][j][k] += s[i][j][k];
    }
    int L = min(n, m) / 2;
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i <= L; ++i) {
      memset(ts, 0, sizeof(ts));
      for (int x = i; x <= n - i; ++x) {
        for (int y = i; y <= m - i; ++y) {
          ts[x][y] = 1;
          if (cal(x - i, y - i, x, y, 0) != i * i) ts[x][y] = 0;
          if (cal(x - i, y, x, y + i, 1) != i * i) ts[x][y] = 0;
          if (cal(x, y - i, x + i, y, 2) != i * i) ts[x][y] = 0;
          if (cal(x, y, x + i, y + i, 3) != i * i) ts[x][y] = 0;
        }
      }
      for (int x = 1; x <= n; ++x) {
        for (int y = 1; y <= m; ++y) ts[x][y] += ts[x][y - 1];
        for (int y = 1; y <= m; ++y) ts[x][y] += ts[x - 1][y];
      }
      for (int j = 0; j < Q; ++j) {
        if (cal2(sx[j] - 2 + i, sy[j] - 2 + i, ex[j] + 0 - i, ey[j] + 0 - i) !=
            0)
          ans[j] = i * i;
      }
    }
    for (int i = 0; i < Q; ++i) printf("%d\n", 4 * ans[i]);
  }
  return 0;
}
