/*
author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
struct FenwickTree {
vector<int> bit; // binary indexed tree
int n;
FenwickTree(int n) {
this->n = n;
bit.assign(n, 0);
}
FenwickTree(vector<int> a) : FenwickTree(a.size()) {
for (size_t i = 0; i < a.size(); i++)
add(i, a[i]);
}
int sum(int r) {
int ret = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
ret += bit[r];
return ret;
}
int sum(int l, int r) {
return sum(r) - sum(l - 1);
}
void add(int idx, int delta) {
for (; idx < n; idx = idx | (idx + 1))
bit[idx] += delta;
}
};
int sum(int x, int y){return x + y;}
bool grid[1001][1001];
int dp[1001][1001];
vector<FenwickTree> row_updates(1001, FenwickTree(1001));
void build_dp(int n, int m)
{
dp[0][0] = dp[1][0] = dp[0][1] = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
dp[i][j] = grid[i][j] + dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1];
}
}
void update(int i, int j, int n)
{
int delta = -1;
if(grid[i][j] == 0) // it was empty
delta = 1; // now it has a tree
grid[i][j] = !grid[i][j]; // switch the state
for(int k = i; k <= n; k++)
row_updates[k].add(j, delta);
}
int getDP(int x, int y)
{
return dp[x][y] + row_updates[x].sum(y);
}
int query(int x1, int y1, int x2, int y2)
{
return getDP(x2,y2) - getDP(x2,y1-1) - getDP(x1-1,y2) + getDP(x1-1,y1-1);
}
int main() {
fast_io;
int n,q;
cin >> n >> q;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
char ch;
cin >> ch;
if(ch == '*')
grid[i][j] = 1;
else grid[i][j] = 0;
}
}
build_dp(n,n);
while(q--)
{
int t;
cin >> t;
if(t == 1)
{
int x,y;
cin >> x >> y;
update(x,y,n);
}
else
{
int x1,x2,y1,y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << query(x1,y1,x2,y2) << '\n';
}
}
return 0;
}
LyoKICAgIGF1dGhvcjoga2FydGlrODgwMAoqLwojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGZyKGEsYikgZm9yKGxsIGkgPSBhOyBpIDwgYjsgaSsrKQojZGVmaW5lIG1vZCAxMDAwMDAwMDA3CiNkZWZpbmUgaW5mICgxTEw8PDYwKQojZGVmaW5lIGFsbCh4KSAoeCkuYmVnaW4oKSwgKHgpLmVuZCgpCiNkZWZpbmUgcHJEb3VibGUoeCkgY291dCA8PCBmaXhlZCA8PCBzZXRwcmVjaXNpb24oMTApIDw8IHgKI2RlZmluZSB0cmlwbGV0IHBhaXI8bGwscGFpcjxsbCxsbD4+CiNkZWZpbmUgZmFzdF9pbyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTtjaW4udGllKE5VTEwpCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgRmVud2lja1RyZWUgewogICAgdmVjdG9yPGludD4gYml0OyAgLy8gYmluYXJ5IGluZGV4ZWQgdHJlZQogICAgaW50IG47CgogICAgRmVud2lja1RyZWUoaW50IG4pIHsKICAgICAgICB0aGlzLT5uID0gbjsKICAgICAgICBiaXQuYXNzaWduKG4sIDApOwogICAgfQoKICAgIEZlbndpY2tUcmVlKHZlY3RvcjxpbnQ+IGEpIDogRmVud2lja1RyZWUoYS5zaXplKCkpIHsKICAgICAgICBmb3IgKHNpemVfdCBpID0gMDsgaSA8IGEuc2l6ZSgpOyBpKyspCiAgICAgICAgICAgIGFkZChpLCBhW2ldKTsKICAgIH0KCiAgICBpbnQgc3VtKGludCByKSB7CiAgICAgICAgaW50IHJ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gLy8gc3dpdGNoIHRoZSBzdGF0ZQogICAgZm9yKGludCBrID0gaTsgayA8PSBuOyBrKyspCiAgICAgICAgcm93X3VwZGF0ZXNba10uYWRkKGosIGRlbHRhKTsKfQoKaW50IGdldERQKGludCB4LCBpbnQgeSkKewogICAgcmV0dXJuIGRwW3hdW3ldICsgcm93X3VwZGF0ZXNbeF0uc3VtKHkpOwp9CgppbnQgcXVlcnkoaW50IHgxLCBpbnQgeTEsIGludCB4MiwgaW50IHkyKQp7CiAgICByZXR1cm4gZ2V0RFAoeDIseTIpIC0gZ2V0RFAoeDIseTEtMSkgLSBnZXREUCh4MS0xLHkyKSArIGdldERQKHgxLTEseTEtMSk7Cn0KCmludCBtYWluKCkgewogICBmYXN0X2lvOwogICBpbnQgbixxOwogICBjaW4gPj4gbiA+PiBxOwoKICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspCiAgIHsKICAgICAgIGZvcihpbnQgaiA9IDE7IGogPD0gbjsgaisrKQogICAgICAgewogICAgICAgICAgIGNoYXIgY2g7CiAgICAgICAgICAgY2luID4+IGNoOwogICAgICAgICAgIGlmKGNoID09ICcqJykKICAgICAgICAgICAgICAgIGdyaWRbaV1bal0gPSAxOwogICAgICAgICAgIGVsc2UgZ3JpZFtpXVtqXSA9IDA7CiAgICAgICB9CiAgIH0KCiAgIGJ1aWxkX2RwKG4sbik7CgogICB3aGlsZShxLS0pCiAgIHsKICAgICAgICBpbnQgdDsKICAgICAgICBjaW4gPj4gdDsKICAgICAgICBpZih0ID09IDEpCiAgICAgICAgewogICAgICAgICAgICBpbnQgeCx5OwogICAgICAgICAgICBjaW4gPj4geCA+PiB5OwogICAgICAgICAgICB1cGRhdGUoeCx5LG4pOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpbnQgeDEseDIseTEseTI7CiAgICAgICAgICAgIGNpbiA+PiB4MSA+PiB5MSA+PiB4MiA+PiB5MjsKICAgICAgICAgICAgY291dCA8PCBxdWVyeSh4MSx5MSx4Mix5MikgPDwgJ1xuJzsKICAgICAgICB9CiAgIH0KICAgcmV0dXJuIDA7Cn0K