#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w;
	cin >>h>>w;
	VVi a(h,Vi(w,0));
	int bef;
	vector<pair<pair<int,int>,pair<int,int>>>ans;
	rep(i,h){
		rep(j,w){
			cin>>bef;
			a[i][j]+=bef;
			if(a[i][j]%2){
				if(j!=w-1){
					ans.push_back(mp(mp(i,j),mp(i,j+1)));
					a[i][j+1]++;
					a[i][j]--;
				}else if(i!=h-1){
					ans.push_back(mp(mp(i, j), mp(i+1, j )));
					a[i+1][j ]++;
					a[i][j]--;
				}
			}
		}
	}
	cout<<ans.size()<<endl;
	rep(i,ans.size()){
		printf("%d %d %d %d\n",1+ans[i].F.F,1+ans[i].F.S,1+ans[i].S.F,1+ans[i].S.S);
	}
}
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;

char s[1000000];
ll t[3][1000001];

int main() {
  int n, q;
  scanf("%d%s%d", &n, s, &q);

  V D, C;
  rep(i, n) {
    rep(j, 3) t[j][i+1] = t[j][i];
    switch(s[i]){
      case 'D':
        ++t[0][i+1];
        D.push_back(i+1);
        break;
      case 'M':
        ++t[1][i+1];
        break;
      case 'C':
        ++t[2][i+1];
        C.push_back(i);
        break;
    }
  }

  ll suma = 0, sumc = 0;
  for (auto &a : D) suma += t[1][a] * t[2][a];
  for (auto &c : C) sumc += t[1][c] * t[0][c];

  rep(_, q) {
    int k; 
    scanf("%d", &k);
    ll ans = suma + sumc;
    for (auto &a : D) ans -= t[1][a] * t[2][min(a+k-1, n)];
    for (auto &c : C) ans -= t[1][c] * t[0][max(c-k+1, 0)];
    printf("%lld\n", ans);
  }
  return 0;
}
