// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; typedef long long ll; #define endl '\n' #define all(x) (x).begin(),(x).end() template bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); class UnionFind{ public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector parent; UnionFind(int N){ parent = vector(N,-1); } int root(int A){ if(parent[A] < 0) return A; return parent[A]=root(parent[A]); } int size(int A){ return -parent[root(A)]; } bool unite(int A, int B) { A = root(A), B = root(B); if(A == B) return false; if(size(A) < size(B)) swap(A,B); parent[A] += parent[B]; parent[B] = A; return true; } bool same(int A, int B){ return root(A)==root(B); } }; vector> v(100010); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n,m,q; cin>>n>>m>>q; int nn = n*7; UnionFind uni(nn); string s[n]; for(int i=0;i>s[i]; for(int j=0;j<7;j++){ if(s[i][j] == '1' && s[i][(j+6)%7] == '1'){ uni.unite(j+i*7,(j+6)%7+i*7); } } } for(int i=0;i>a>>b; a--,b--; v[a].push_back(b); v[b].push_back(a); for(int j=0;j<7;j++){ if(s[a][j] == s[b][j] && s[a][j] == '1'){ uni.unite(j+a*7, j+b*7); } } } while(q--){ int t,x,y; cin>>t>>x>>y; y--; x--; if(t == 1){ s[x][y] = '1'; int ny; ny = (y+1)%7; if(s[x][ny]=='1')uni.unite(ny+x*7,y+x*7); ny = (y+6)%7; if(s[x][ny]=='1')uni.unite(ny+x*7,y+x*7); for(auto i:v[x]){ if(s[i][y] == '1')uni.unite(y+x*7,y+i*7); } } else{ cout << uni.size(0+x*7) << endl; } } }