#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
int a[maxn][maxn];
int num[5][maxn][maxn];
char s[maxn][maxn];
int val[maxn][maxn];
int f[10][10][maxn][maxn];
int lg[maxn];
void Build_2D_Sparse_Table(int n, int m) {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[0][0][i][j] = val[i][j];
    }
  }
  for (int i = 2; i < maxn; i++) lg[i] = 1 + lg[i / 2];
  for (int i = 1; i <= n; i++)
    for (int k2 = 1; (1 << k2) <= m; k2++)
      for (int j = 1; j <= m - (1 << k2) + 1; j++)
        f[0][k2][i][j] =
            max(f[0][k2 - 1][i][j], f[0][k2 - 1][i][j + (1 << (k2 - 1))]);
  for (int k1 = 1; (1 << k1) <= n; k1++)
    for (int i = 1; i <= n - (1 << k1) + 1; i++)
      for (int k2 = 0; (1 << k2) <= m; k2++)
        for (int j = 1; j <= m - (1 << k2) + 1; j++)
          f[k1][k2][i][j] =
              max(f[k1 - 1][k2][i][j], f[k1 - 1][k2][i + (1 << (k1 - 1))][j]);
}
int Query(int x1, int y1, int x2, int y2) {
  int k1 = lg[x2 - x1 + 1], k2 = lg[y2 - y1 + 1];
  x2 = x2 - (1 << k1) + 1;
  y2 = y2 - (1 << k2) + 1;
  return max(max(f[k1][k2][x1][y1], f[k1][k2][x1][y2]),
             max(f[k1][k2][x2][y1], f[k1][k2][x2][y2]));
}
bool check(int bx, int by, int ex, int ey, int x) {
  bx += x - 1, by += x - 1, ex -= x, ey -= x;
  if (bx > ex || by > ey) return 0;
  return Query(bx, by, ex, ey) >= x;
}
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'R') {
        num[1][i][j] =
            min({num[1][i - 1][j], num[1][i][j - 1], num[1][i - 1][j - 1]});
        num[1][i][j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      if (s[i][j] == 'G') {
        num[2][i][j] =
            min({num[2][i - 1][j], num[2][i][j + 1], num[2][i - 1][j + 1]});
        num[2][i][j]++;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'Y') {
        num[3][i][j] =
            min({num[3][i + 1][j], num[3][i][j - 1], num[3][i + 1][j - 1]});
        num[3][i][j]++;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (s[i][j] == 'B') {
        num[4][i][j] =
            min({num[4][i + 1][j + 1], num[4][i + 1][j], num[4][i][j + 1]});
        num[4][i][j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      val[i][j] = min({num[1][i][j], num[2][i][j + 1], num[3][i + 1][j],
                       num[4][i + 1][j + 1]});
    }
  }
  Build_2D_Sparse_Table(n, m);
  while (q--) {
    int bx, by, ex, ey;
    scanf("%d%d%d%d", &bx, &by, &ex, &ey);
    int L = 0, R = min(ex - bx, ey - by);
    int ans;
    while (L <= R) {
      int mid = L + R >> 1;
      if (check(bx, by, ex, ey, mid))
        ans = mid, L = mid + 1;
      else
        R = mid - 1;
    }
    cout << ans * ans * 4 << endl;
  }
  return 0;
}
