#include <bits/stdc++.h>
using namespace std;
int logn[505], cnt[505][505][4], st[505][505][10][10];
void pre() {
  logn[1] = 0, logn[2] = 1;
  for (int i = (3); i <= (500); ++i) logn[i] = logn[i >> 1] + 1;
}
int mxa(int r1, int c1, int r2, int c2) {
  int k = logn[r2 - r1 + 1], l = logn[c2 - c1 + 1];
  return max(max(st[r1][c1][k][l], st[r1][c2 - (1 << l) + 1][k][l]),
             max(st[r2 - (1 << k) + 1][c1][k][l],
                 st[r2 - (1 << k) + 1][c2 - (1 << l) + 1][k][l]));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  pre();
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      char c;
      cin >> c;
      cnt[i][j][0] += (c == 'R');
      cnt[i][j][1] += (c == 'G');
      cnt[i][j][2] += (c == 'Y');
      cnt[i][j][3] += (c == 'B');
    }
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      cnt[i][j][0] +=
          cnt[i - 1][j][0] + cnt[i][j - 1][0] - cnt[i - 1][j - 1][0];
      cnt[i][j][1] +=
          cnt[i - 1][j][1] + cnt[i][j - 1][1] - cnt[i - 1][j - 1][1];
      cnt[i][j][2] +=
          cnt[i - 1][j][2] + cnt[i][j - 1][2] - cnt[i - 1][j - 1][2];
      cnt[i][j][3] +=
          cnt[i - 1][j][3] + cnt[i][j - 1][3] - cnt[i - 1][j - 1][3];
    }
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      int mx = 0;
      for (int k = 7; k >= 0; k--) {
        int tlen = mx + (1 << k);
        if (i - tlen < 0 || i + tlen > n || j - tlen < 0 || j + tlen > m)
          continue;
        bool ok = 1;
        ok &= (cnt[i][j][0] - cnt[i - tlen][j][0] - cnt[i][j - tlen][0] +
                   cnt[i - tlen][j - tlen][0] ==
               tlen * tlen);
        ok &= (cnt[i][j + tlen][1] - cnt[i - tlen][j + tlen][1] - cnt[i][j][1] +
                   cnt[i - tlen][j][1] ==
               tlen * tlen);
        ok &= (cnt[i + tlen][j][2] - cnt[i][j][2] - cnt[i + tlen][j - tlen][2] +
                   cnt[i][j - tlen][2] ==
               tlen * tlen);
        ok &= (cnt[i + tlen][j + tlen][3] - cnt[i][j + tlen][3] -
                   cnt[i + tlen][j][3] + cnt[i][j][3] ==
               tlen * tlen);
        if (ok) mx = tlen;
      }
      st[i][j][0][0] = mx;
    }
  for (int k = (0); k <= (logn[n]); ++k)
    for (int l = (0); l <= (logn[m]); ++l)
      for (int i = 1; i + (1 << k) - 1 <= n; i++)
        for (int j = 1; j + (1 << l) - 1 <= m; j++) {
          if (k == 0 && l == 0)
            continue;
          else if (k == 0 && l != 0)
            st[i][j][k][l] =
                max(st[i][j][k][l - 1], st[i][j + (1 << (l - 1))][k][l - 1]);
          else if (k != 0 && l == 0)
            st[i][j][k][l] =
                max(st[i][j][k - 1][l], st[i + (1 << (k - 1))][j][k - 1][l]);
          else
            st[i][j][k][l] = max(
                max(st[i][j][k - 1][l - 1],
                    st[i][j + (1 << (l - 1))][k - 1][l - 1]),
                max(st[i + (1 << (k - 1))][j][k - 1][l - 1],
                    st[i + (1 << (k - 1))][j + (1 << (l - 1))][k - 1][l - 1]));
        }
  for (int i = (1); i <= (q); ++i) {
    int r1, r2, c1, c2, ans = 0;
    cin >> r1 >> c1 >> r2 >> c2;
    for (int k = 7; k >= 0; k--) {
      int tans = ans + (1 << k);
      if (r1 + (tans << 1) - 1 > r2 || c1 + (tans << 1) - 1 > c2) continue;
      if (mxa(r1 + tans - 1, c1 + tans - 1, r2 - tans, c2 - tans) >= tans)
        ans = tans;
    }
    cout << (ans << 1) * (ans << 1) << '\n';
  }
}
