#include <bits/stdc++.h>
using namespace std;
int N, M;
int BIT_J[2000][2000];
int BIT_O[2000][2000];
int BIT_I[2000][2000];
void add_J(int a, int b, int w) {
  for (int x = a; x <= N; x += x & -x) {
    for (int y = b; y <= M; y += y & -y) {
      BIT_J[x][y] += w;
    }
  }
}
int sum_J(int a, int b) {
  int ret = 0;
  for (int x = a; x > 0; x -= x & -x) {
    for (int y = b; y > 0; y -= y & -y) {
      ret += BIT_J[x][y];
    }
  }
  return ret;
}
void add_O(int a, int b, int w) {
  for (int x = a; x <= N; x += x & -x) {
    for (int y = b; y <= M; y += y & -y) {
      BIT_O[x][y] += w;
    }
  }
}
int sum_O(int a, int b) {
  int ret = 0;
  for (int x = a; x > 0; x -= x & -x) {
    for (int y = b; y > 0; y -= y & -y) {
      ret += BIT_O[x][y];
    }
  }
  return ret;
}
void add_I(int a, int b, int w) {
  for (int x = a; x <= N; x += x & -x) {
    for (int y = b; y <= M; y += y & -y) {
      BIT_I[x][y] += w;
    }
  }
}
int sum_I(int a, int b) {
  int ret = 0;
  for (int x = a; x > 0; x -= x & -x) {
    for (int y = b; y > 0; y -= y & -y) {
      ret += BIT_I[x][y];
    }
  }
  return ret;
}
string map[1024];
int main() {
  int K;
  cin >> M >> N >> K;
  for (int i = 0; i < M; i++) {
    cin >> map[i];
  }
  N = 1024;
  M = 1024;
  for (int i = 0; i <= M; i++) {
    for (int j = 0; j <= N; j++) {
      BIT_J[i][j] = 0;
      BIT_O[i][j] = 0;
      BIT_I[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (map[i][j] == 'J') {
        add_J(j + 1, i + 1, 1);
      } else if (map[i][j] == 'O') {
        add_O(j + 1, i + 1, 1);
      } else if (map[i][j] == 'I') {
        add_I(j + 1, i + 1, 1);
      }
    }
  }
  M = 4;
  N = 7;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      printf("%d ", BIT_J[j][i]);
    }
    printf("\n");
  }
  printf("\n");
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      printf("%d ", BIT_O[j][i]);
    }
    printf("\n");
  }
  printf("\n");
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      printf("%d ", BIT_I[j][i]);
    }
    printf("\n");
  }
  printf("\n");
  int a, b, c, d;
  for (int loop = 0; loop < K; loop++) {
    cin >> b >> a >> d >> c;
    printf("%d ", sum_J(c, d) + sum_J(a - 1, b - 1) - sum_J(a - 1, d) -
                      sum_J(c, b - 1));
    printf("%d ", sum_O(c, d) + sum_O(a - 1, b - 1) - sum_O(a - 1, d) -
                      sum_O(c, b - 1));
    printf("%d\n", sum_I(c, d) + sum_I(a - 1, b - 1) - sum_I(a - 1, d) -
                       sum_I(c, b - 1));
  }
  return 0;
}
