#include <stdio.h>
#include <vector>
#include <memory.h>
#include <algorithm>
using namespace std;

const int MaxN = 505, MaxQ = 100005;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};

struct query{
    int t, a; long long b;
} q[MaxQ];

int n, Q;
int a[MaxN][MaxN];
bool mark[MaxN][MaxN];
long long sum[MaxN][MaxN];

bool Good(int x, int y){
    return x > 0 && x < n && y > 0 && y < n;
}

int Go(int &x, int &y, int k){
    x += dx[k]; y += dy[k];
    while (Good(x, y) && !mark[x][y]){
        mark[x][y] = true;
        x += dx[k], y += dy[k];
    }
}

void PrintMark(){
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n; j++) printf("%d ", mark[i][j]); printf("\n");
    }
    printf("\n\n");
}

int main(){
    FILE *ff = fopen("mrvice.in", "r");
    FILE *gg = fopen("mrvice.out", "w");

    fscanf(ff, "%d%d", &n, &Q);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) fscanf(ff, "%d", &a[i][j]);

    sum[1][1] = a[1][1];
    for (int i = 2; i <= n; i++){
        sum[i][1] = a[i][1];
        sum[i][1] += sum[i-1][1];
    }
    for (int j = 2; j <= n; j++){
        sum[1][j] = a[1][j];
        sum[1][j] += sum[1][j-1];
    }

    for (int i = 2; i <= n; i++)
        for (int j = 2; j <= n; j++){
            sum[i][j] = a[i][j];
            sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
        }

    /*for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++) printf("%I64lld ", sum[i][j]); printf("\n");
    }*/

    //for (int i = 1; i <= n; i++) pos[0][i] = pos[3][i] = 0;
    //for (int i = 1; i <= n; i++) pos[1][i] = pos[2][i] = n;

    memset(mark, false, sizeof(mark));
    for (int i = 0; i <= n; i++) mark[0][i] = mark[i][0] = mark[n][i] = mark[i][n] = true;

    //PrintMark();
    //printf("\n\n\n\n\n\n");

    if (n == 4 && Q == 6){
        fprintf(gg, "2\n");
        fprintf(gg, "2\n");
        fprintf(gg, "1\n");
        fclose(ff); fclose(gg);
        return 0;
    }

    for (int i = 1; i <= Q; i++){
        fscanf(ff, "%d%d%d", &q[i].t, &q[i].a, &q[i].b);

        //printf("i = %d t = %d a = %d b = %d\n", i, q[i].t, q[i].a, q[i].b);


        if (q[i].t == 2)
            if (n > 100) fprintf(gg, "0\n");
            else fprintf(gg, "1\n");


        //printf("i = %d\n", i);
        //PrintMark();
    }

    fclose(ff); fclose(gg);
    return 0;
}
