#include <bits/stdc++.h>
using namespace std;
struct Hash {
  int P = 1777771, MOD[2], PI[2];
  vector<int> h[2], pi[2];
  Hash(string& s) {
    MOD[0] = 999727999;
    MOD[1] = 1070777777;
    PI[0] = 325255434;
    PI[1] = 10018302;
    for (int k = (0); k < (2); k++)
      h[k].resize(s.size() + 1), pi[k].resize(s.size() + 1);
    for (int k = (0); k < (2); k++) {
      h[k][0] = 0;
      pi[k][0] = 1;
      long long p = 1;
      for (int i = (1); i < (s.size() + 1); i++) {
        h[k][i] = (h[k][i - 1] + p * s[i - 1]) % MOD[k];
        pi[k][i] = (1LL * pi[k][i - 1] * PI[k]) % MOD[k];
        p = (p * P) % MOD[k];
      }
    }
  }
  long long get(int s, int e) {
    long long h0 = (h[0][e] - h[0][s] + MOD[0]) % MOD[0];
    h0 = (1LL * h0 * pi[0][s]) % MOD[0];
    long long h1 = (h[1][e] - h[1][s] + MOD[1]) % MOD[1];
    h1 = (1LL * h1 * pi[1][s]) % MOD[1];
    return (h0 << 32) | h1;
  }
};
vector<Hash> horiz, rg, yb;
int n, m;
bool find(int r, int c, int size) {
  if (r + size * 2 > n || c + size * 2 > m) {
    return false;
  }
  int L = c, R = c + size * 2;
  for (int i = (0); i < (size); i++)
    if (horiz[r + i].get(L, R) != rg[size - 1].get(0, size * 2)) return false;
  for (int i = (0); i < (size); i++)
    if (horiz[r + i + size].get(L, R) != yb[size - 1].get(0, size * 2))
      return false;
  return true;
}
map<int, map<int, set<int>>> logos;
set<int>::iterator ite;
int r1, c1, r2, c2, L, R, M;
bool can() {
  map<int, set<int>>::iterator it = logos[M].lower_bound(r1),
                               end = logos[M].end();
  while (it != end && r2 - it->first + 1 >= M * 2) {
    ite = it->second.lower_bound(c1);
    if (ite != it->second.end() && c2 - *ite + 1 >= M * 2) return true;
    it++;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> n >> m >> q;
  if (n == 1 || m == 1) {
    for (int i = (0); i < (q); i++) cout << "0\n";
    return 0;
  }
  vector<string> table(n);
  horiz.reserve(n);
  for (int i = (0); i < (n); i++) {
    table[i].reserve(m);
    cin >> table[i];
    horiz.push_back(Hash(table[i]));
  }
  rg.reserve(n / 2);
  yb.reserve(n / 2);
  string aux = "";
  for (int i = (0); i < (n / 2); i++) {
    aux = "R" + aux + "G";
    rg.push_back(Hash(aux));
  }
  aux = "";
  for (int i = (0); i < (n / 2); i++) {
    aux = "Y" + aux + "B";
    yb.push_back(Hash(aux));
  }
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (m); j++) {
      bool found = true;
      int size = 1, r = i, c = j;
      while (found && r >= 0 && c >= 0) {
        found = find(r, c, size);
        if (found) {
          logos[size][r].insert(c);
        }
        r--;
        c--;
        size++;
      }
    }
  for (int i = (0); i < (q); i++) {
    cin >> r1 >> c1 >> r2 >> c2;
    r1--;
    c1--;
    r2--;
    c2--;
    L = 0;
    R = (min(r2 - r1, c2 - c1) + 1) / 2;
    while (L < R) {
      M = (L + R + 1) / 2;
      if (can())
        L = M;
      else
        R = M - 1;
    }
    cout << ((2 * L) * (2 * L)) << '\n';
  }
  return 0;
}
