#include <bits/stdc++.h>
using namespace std;
template <class T>
vector<T> iarr(int n) {
  vector<T> a;
  while (n--) {
    T _v;
    cin >> _v, a.push_back(_v);
  }
  return a;
}
template <class T>
vector<vector<T>> imat(int n, int m) {
  vector<vector<T>> ma(n, vector<T>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> ma[i][j];
  return ma;
}
struct OfflineSum2D {
  OfflineSum2D(int n, int m) {
    this->n = n;
    this->m = m;
    acc = vector<vector<int>>(n + 1, vector<int>(m + 1, 0));
  }
  void add(int i, int j, int v) { acc[i + 1][j + 1] += v; }
  void compute() {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        acc[i][j] += acc[i - 1][j] + acc[i][j - 1] - acc[i - 1][j - 1];
      }
    }
  }
  int get(int i, int j, int p, int q) {
    i++;
    j++;
    p++;
    q++;
    return acc[p][q] - acc[i - 1][q] - acc[p][j - 1] + acc[i - 1][j - 1];
  }
  int n, m;
  vector<vector<int>> acc;
};
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  int q;
  cin >> q;
  auto board = imat<char>(n, m);
  vector<OfflineSum2D> raw(4, OfflineSum2D(n, m));
  vector<OfflineSum2D> nano(251, OfflineSum2D(n, m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (board[i][j] == 'R') raw[0].add(i, j, 1);
      if (board[i][j] == 'G') raw[1].add(i, j, 1);
      if (board[i][j] == 'B') raw[2].add(i, j, 1);
      if (board[i][j] == 'Y') raw[3].add(i, j, 1);
    }
  }
  for (int i = 0; i < 4; i++) {
    raw[i].compute();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++) {
        if (i + 2 * k - 1 >= n || j + 2 * k - 1 >= m) {
          continue;
        }
        if (raw[0].get(i, j, i + k - 1, j + k - 1) != k * k ||
            raw[1].get(i, j + k, i + k - 1, j + 2 * k - 1) != k * k ||
            raw[2].get(i + k, j + k, i + 2 * k - 1, j + 2 * k - 1) != k * k ||
            raw[3].get(i + k, j, i + 2 * k - 1, j + k - 1) != k * k) {
          continue;
        }
        nano[k].add(i, j, 1);
      }
    }
  }
  for (int i = 1; i < 251; i++) {
    nano[i].compute();
  }
  for (int qq = 0; qq < q; qq++) {
    int r1;
    cin >> r1;
    int c1;
    cin >> c1;
    int r2;
    cin >> r2;
    int c2;
    cin >> c2;
    r1--;
    c1--;
    r2--;
    c2--;
    int maxi = 0;
    for (int k = 250; k > 0; k--) {
      if (r2 - 2 * k + 1 < r1 || c2 - 2 * k + 1 < c1) {
        continue;
      }
      if (nano[k].get(r1, c1, r2 - 2 * k + 1, c2 - 2 * k + 1) > 0) {
        maxi = k;
        break;
      }
    }
    cout << 2 * maxi * 2 * maxi << "\n";
  }
  return 0;
}
