#include <bits/stdc++.h>
using namespace std;
int nowr[4][555][555], mat[555][555], rall[555][555];
int sum[555][555], co[555][555], res[333333];
char s[555];
struct qu {
  int l, r, u, d, id;
};
vector<qu> vq;
vector<pair<int, int> > vch[555];
int main() {
  int n, m, q, a, b, c, d;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i < n + 1; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j < m + 1; j++) {
      if (s[j] == 'G')
        mat[i][j] = 0;
      else if (s[j] == 'Y')
        mat[i][j] = 1;
      else if (s[j] == 'R')
        mat[i][j] = 2;
      else
        mat[i][j] = 3;
    }
  }
  for (int k = 0; k < 4; k++)
    for (int i = 1; i < n + 1; i++)
      for (int j = 1; j < m + 1; j++) {
        if (mat[i][j] != k)
          nowr[k][i][j] = 0;
        else
          nowr[k][i][j] = min({nowr[k][i][j - 1], nowr[k][i - 1][j - 1],
                               nowr[k][i - 1][j]}) +
                          1;
      }
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < m + 1; j++)
      if (mat[i][j] == 3) {
        int k = nowr[3][i][j];
        if (nowr[1][i][j - k] < k || nowr[0][i - k][j] < k ||
            nowr[2][i - k][j - k] < k)
          continue;
        rall[i][j] = k * 2;
        vch[k * 2].push_back({i, j});
      }
  for (int i = 1; i < q + 1; i++)
    scanf("%d%d%d%d", &a, &b, &c, &d), vq.push_back({a, c, b, d, i});
  vector<qu> tmp;
  for (int i = min(n, m); i; i--)
    if (!vch[i].empty()) {
      tmp.clear();
      for (pair<int, int> p : vch[i]) co[p.first][p.second] = 1;
      for (int i = 1; i < n + 1; i++)
        for (int j = 1; j < m + 1; j++)
          sum[i][j] =
              sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + co[i][j];
      for (qu &q : vq) {
        int l = q.l + i - 1, u = q.u + i - 1;
        if (l <= q.r && u <= q.d &&
            sum[q.r][q.d] - sum[l - 1][q.d] - sum[q.r][u - 1] +
                sum[l - 1][u - 1])
          res[q.id] = i;
        else
          tmp.push_back(q);
      }
      for (pair<int, int> p : vch[i]) co[p.first][p.second] = 0;
      swap(vq, tmp);
    }
  for (int i = 1; i < q + 1; i++) printf("%d\n", res[i] * res[i]);
}
