#include "bits/stdc++.h" using namespace std; using ll=long long; using vll=vector< ll>; using vvll=vector< vll>; using vvvll=vector< vvll>; using vvvvll=vector; using dd=double; using vdd=vector< dd>; using vvdd=vector< vdd>; using pll=pair; using tll=tuple; using qll=tuple; using vpll=vector< pll>; constexpr ll INF = 1LL << 60; struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<::max_digits10); } } fast; #define REPS(i, S, E) for (ll i = (S); i <= (E); i++) #define REP(i, N) REPS(i, 0, (N)-1) #define DEPS(i, S, E) for (ll i = (E); i >= (S); i--) #define DEP(i, N) DEPS(i, 0, (N)-1) #define rep(i, S, E) for (ll i = (S); i <= (E); i++) #define dep(i, E, S) for (ll i = (E); i >= (S); i--) #define each(e, v) for (auto&& e : v) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; } template inline T MaxE(vector&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; } template inline T MinE(vector&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; } template inline T MaxE(vector &v) { return MaxE(v,0,(ll)v.size()-1); } template inline T MinE(vector &v) { return MinE(v,0,(ll)v.size()-1); } template inline T Sum(vector &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; } template inline T Sum(vector &v) { return Sum(v,0,v.size()-1); } template inline ll sz(T &v){ return (ll)v.size(); } inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } #if 0 #include using namespace atcoder; #endif //tuple3用テンプレート using vtll=vector< tll>; using vvtll=vector; template inline tuple& operator+=(tuple &a,const tuple &b){ get<0>(a)+=get<0>(b); get<1>(a)+=get<1>(b); get<2>(a)+=get<2>(b); return a; } template inline tuple& operator-=(tuple &a,const tuple &b){ get<0>(a)-=get<0>(b); get<1>(a)-=get<1>(b); get<2>(a)-=get<2>(b); return a; } template inline tuple& operator*=(tuple &a,const tuple &b){ get<0>(a)*=get<0>(b); get<1>(a)*=get<1>(b); get<2>(a)*=get<2>(b); return a; } template inline tuple& operator/=(tuple &a,const tuple &b){ get<0>(a)/=get<0>(b); get<1>(a)/=get<1>(b); get<2>(a)/=get<2>(b); return a; } template inline tuple& operator%=(tuple &a,const tuple &b){ get<0>(a)%=get<0>(b); get<1>(a)%=get<1>(b); get<2>(a)%=get<2>(b); return a; } template inline tuple& operator+=(tuple &a,Q b){ get<0>(a)+=b; get<1>(a)+=b; get<2>(a)+=b; return a; } template inline tuple& operator-=(tuple &a,Q b){ get<0>(a)-=b; get<1>(a)-=b; get<2>(a)-=b; return a; } template inline tuple& operator*=(tuple &a,Q b){ get<0>(a)*=b; get<1>(a)*=b; get<2>(a)*=b; return a; } template inline tuple& operator/=(tuple &a,Q b){ get<0>(a)/=b; get<1>(a)/=b; get<2>(a)/=b; return a; } template inline tuple& operator%=(tuple &a,Q b){ get<0>(a)%=b; get<1>(a)%=b; get<2>(a)%=b; return a; } template inline tuple operator+(const tuple &a,Q b){ tuple c=a; return c+=b; } template inline tuple operator-(const tuple &a,Q b){ tuple c=a; return c-=b; } template inline tuple operator*(const tuple &a,Q b){ tuple c=a; return c*=b; } template inline tuple operator/(const tuple &a,Q b){ tuple c=a; return c/=b; } template inline tuple operator%(const tuple &a,Q b){ tuple c=a; return c%=b; } template inline tuple operator-(Q b,const tuple &a){ tuple c=-a; return c+=b; } template inline tuple operator-(const tuple &a){ tuple c=a; return c*=(-1); } template inline ostream &operator<<(ostream &os,const tuple &a){ return os << get<0>(a) << ' ' << get<1>(a) << ' ' << get<2>(a); } vvll cinGraph(ll nodeNum,ll edgeNum,bool isDirected){//無向false、有向true vvll to(nodeNum); rep(i,0,edgeNum-1){ ll v,u; cin >> v >> u; v--; u--; to[v].push_back(u); if (!isDirected) to[u].push_back(v); } return move(to); } class UnionFindTree{ private: vll par,rank,size; public: UnionFindTree(ll num): par(num),rank(num),size(num,1){ rep(i,0,num-1) par[i] = i; } bool Same(ll x,ll y) { return Root(x) == Root(y); } ll Root(ll x) { return (par[x] == x) ? x : par[x]=Root(par[x]); } ll Size(ll x){ return size[Root(x)]; } void Unite(ll x,ll y){ x = Root(x); y = Root(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else par[y] = x; if (rank[x] == rank[y]) rank[x]++; size[x] = size[y] = size[x] + size[y]; } }; /* UnionFindTree uft(N); uft.Unite(x,y); bool b = uft.Same(x,y); ll num = uft.Size(x); ll v = uft.Root(x); */ void solve() { ll M=7; ll n,m,q; cin >> n >> m >> q; vector s(n); rep(i,0,n-1){ string s_; cin>>s_; s[i]=s_; } vvll to = cinGraph(n,m,false); //vector> uv(m); //rep(i,0,m-1){ ll u; ll v; cin>>u>>v; uv[i]={u,v}; } UnionFindTree uft(n*M); //M*v+c rep(v,0,n-1){ each(u,to[v]){ if (u> kind >> v >> c; v--; c--; if (kind==1){ s[v][c]='1'; each(u,to[v]){ if (s[u][c]=='1'){ uft.Unite(M*v+c,M*u+c); } } if (s[v][(c+1)%M]=='1'){ uft.Unite(M*v+c,M*v+(c+1)%M); } if (s[v][(c+M-1)%M]=='1'){ uft.Unite(M*v+c,M*v+(c+M-1)%M); } } else{ ans.push_back(uft.Size(M*v)); } } each(e,ans) cout << e << '\n'; } int main(){ #if 1 solve(); #else ll t; cin >> t; rep(i, 0, t-1){ solve(); } #endif return 0; }