#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int S[255][505][505];
char c[505][505];
int T[5][505][505];
int Id(char c) {
  if (c == 'R') return 0;
  if (c == 'Y') return 1;
  if (c == 'G') return 2;
  if (c == 'B') return 3;
  return -1;
}
int ok(int x1, int y1, int x2, int y2, int c) {
  int pig =
      T[c][x2][y2] - T[c][x1 - 1][y2] - T[c][x2][y1 - 1] + T[c][x1 - 1][y1 - 1];
  return pig == (x2 - x1 + 1) * (y2 - y1 + 1);
}
int check(int x1, int y1, int x2, int y2, int l) {
  return S[l][x2][y2] - S[l][x1 - 1][y2] - S[l][x2][y1 - 1] +
             S[l][x1 - 1][y1 - 1] >=
         1;
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", c[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int l = 0; l < 4; l++) {
        T[l][i][j] = Id(c[i][j]) == l;
        T[l][i][j] += T[l][i - 1][j] + T[l][i][j - 1] - T[l][i - 1][j - 1];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] != 'R') continue;
      for (int l = 1; i + 2 * l - 1 <= n and j + 2 * l - 1 <= m; l++) {
        if (ok(i, j, i + l - 1, j + l - 1, 0) and
            ok(i + l, j, i + 2 * l - 1, j + l - 1, 1) and
            ok(i, j + l, i + l - 1, j + 2 * l - 1, 2) and
            ok(i + l, j + l, i + 2 * l - 1, j + 2 * l - 1, 3)) {
          S[l][i][j] = 1;
        }
      }
    }
  }
  int adsf = min(n, m);
  for (int l = 1; l <= adsf / 2; l++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        S[l][i][j] += S[l][i - 1][j] + S[l][i][j - 1] - S[l][i - 1][j - 1];
      }
    }
  }
  while (q--) {
    int l = 1, r, ans = 0;
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    r = min(x2 - x1 + 1, y2 - y1 + 1) / 2;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(x1, y1, x2 - 2 * mid + 1, y2 - 2 * mid + 1, mid)) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    printf("%d\n", ans * ans * 4);
  }
  return 0;
}
