#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, m, q;
char F[N][N];
int u[N][N], l[N][N], f[N][N], s[N][N][N >> 1];
bool check(int len, int x1, int y1, int x2, int y2) {
  return s[x2][y2][len] - s[x1 - 1][y2][len] - s[x2][y1 - 1][len] +
             s[x1 - 1][y1 - 1][len] >
         0;
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; i++) scanf("%s", F[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      u[i][j] = l[i][j] = f[i][j] = 1;
      if (F[i][j] == F[i - 1][j]) u[i][j] = u[i - 1][j] + 1;
      if (F[i][j] == F[i][j - 1]) l[i][j] = l[i][j - 1] + 1;
      if (F[i][j] == F[i - 1][j - 1])
        f[i][j] = min({u[i][j], l[i][j], f[i - 1][j - 1] + 1});
      if (F[i][j] == 'B' && F[i - f[i][j]][j] == 'G' &&
          f[i - f[i][j]][j] >= f[i][j] && l[i - f[i][j]][j] == f[i][j] &&
          F[i][j - f[i][j]] == 'Y' && f[i][j - f[i][j]] >= f[i][j] &&
          u[i][j - f[i][j]] == f[i][j] && F[i - f[i][j]][j - f[i][j]] == 'R' &&
          f[i - f[i][j]][j - f[i][j]] >= f[i][j])
        s[i][j][f[i][j]] = 1;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = 1; k <= min(n, m) >> 1; k++)
        s[i][j][k] += s[i - 1][j][k] + s[i][j - 1][k] - s[i - 1][j - 1][k];
  while (q--) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    int l = 0, r = min(x2 - x1 + 1, y2 - y1 + 1) >> 1;
    while (l < r) {
      int mid = l + r + 1 >> 1;
      if (check(mid, x1 + mid * 2 - 1, y1 + mid * 2 - 1, x2, y2))
        l = mid;
      else
        r = mid - 1;
    }
    printf("%d\n", 4 * l * l);
  }
  return 0;
}
