#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, q;
unordered_map<char, vector<vector<int>>> sum;
vector<vector<vector<int>>> cnt;
bool inside(pair<int, int> a) {
  return a.first >= 0 && a.first < n && a.second >= 0 && a.second < m;
}
int get_sum(vector<vector<int>>& mat, pair<int, int> b, pair<int, int> a) {
  if (!inside(a) || !inside(b)) return 0;
  pair<int, int> temp_a = a, temp_b = b;
  a.first = max(temp_a.first, temp_b.first);
  a.second = max(temp_a.second, temp_b.second);
  b.first = min(temp_a.first, temp_b.first);
  b.second = min(temp_a.second, temp_b.second);
  b.first--, b.second--;
  int res = mat[a.first][a.second];
  if (b.second >= 0) {
    res -= mat[a.first][b.second];
  }
  if (b.first >= 0) {
    res -= mat[b.first][a.second];
  }
  if (b.first >= 0 && b.second >= 0) {
    res += mat[b.first][b.second];
  }
  return res;
}
void to_pref(vector<vector<int>>& mat) {
  for (int i = 0; i < mat.size(); i++) {
    for (int j = 0; j < mat[i].size(); j++) {
      mat[i][j] += get_sum(mat, {0, 0}, {i - 1, j});
      mat[i][j] += get_sum(mat, {0, 0}, {i, j - 1});
      mat[i][j] -= get_sum(mat, {0, 0}, {i - 1, j - 1});
    }
  }
}
template <typename T>
void resize(T& mat) {
  mat.resize(n);
  for (auto& i : mat) i.resize(m);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<vector<char>> col;
  cin >> n >> m >> q;
  resize(col);
  resize(sum['R']);
  resize(sum['G']);
  resize(sum['B']);
  resize(sum['Y']);
  cnt.resize(min(n, m) / 2 + 1);
  for (auto& i : cnt) {
    resize(i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> col[i][j];
      sum[col[i][j]][i][j]++;
    }
  }
  for (auto& i : sum) {
    to_pref(i.second);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int d = 0;
      while (1) {
        int s = (d + 1) * (d + 1);
        if (get_sum(sum['R'], {i - d, j - d}, {i, j}) != s) break;
        if (get_sum(sum['G'], {i - d, j + d + 1}, {i, j + 1}) != s) break;
        if (get_sum(sum['Y'], {i + d + 1, j - d}, {i + 1, j}) != s) break;
        if (get_sum(sum['B'], {i + d + 1, j + d + 1}, {i + 1, j + 1}) != s)
          break;
        cnt[++d][i][j] = 1;
      }
    }
  }
  for (auto& i : cnt) {
    to_pref(i);
  }
  while (q--) {
    pair<int, int> a, b;
    cin >> b.first >> b.second >> a.first >> a.second;
    a.first--, a.second--;
    b.first--, b.second--;
    int l = 0, r = (min(a.first - b.first, a.second - b.second) + 1) / 2 + 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      pair<int, int> temp_a = {a.first - mid, a.second - mid};
      pair<int, int> temp_b = {b.first + (mid - 1), b.second + (mid - 1)};
      if (get_sum(cnt[mid], temp_b, temp_a)) {
        l = mid;
      } else {
        r = mid;
      }
    }
    cout << 4 * l * l << "\n";
  }
  return 0;
}
