#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; class Dis{ public: vector rank,p,siz; Dis(int s){ rank.resize(s,0); p.resize(s,0); siz.resize(s,1); rep(i,s) makeSet(i); } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ if(same(x,y)) return; link(findSet(x),findSet(y)); } void link(int x,int y){ if(rank[x]>rank[y]){ p[y]=x; siz[x]+=siz[y]; } else{ p[x]=y; siz[y]+=siz[x]; if(rank[x]==rank[y]) rank[y]++; } } int findSet(int x){ if(x != p[x]) p[x]=findSet(p[x]); return p[x]; } int size(int x){ return siz[findSet(x)]; } }; vector G[100010]; int main(){ ll n,m,q; cin>>n>>m>>q; Dis ds=Dis(7*n); vector A(n); rep(i,n) cin>>A[i]; rep(i,m){ int x,y; cin>>x>>y; x--,y--; G[x].push_back(y); G[y].push_back(x); } rep(i,n){ rep(j,6){ if(A[i][j]=='1' && A[i][j+1]=='1') ds.unite(7*i+j,7*i+j+1); } if(A[i][0]=='1' && A[i][6]=='1') ds.unite(7*i,7*i+6); } rep(i,n){ rep(j,7){ for(auto t:G[i]){ if(A[i][j]=='1' && A[t][j]=='1') ds.unite(7*i+j,7*t+j); } } } rep(i,q){ int c,x,y; cin>>c>>x>>y; x--,y--; if(c==1){ A[x][y]='1'; if(A[x][(y+1)%7]=='1') ds.unite(7*x+y,7*x+(y+1)%7); if(A[x][(y+6)%7]=='1') ds.unite(7*x+y,7*x+(y+6)%7); for(auto t:G[x]){ if(A[t][y]=='1') ds.unite(7*t+y,7*x+y); } } if(c==2){ cout<