#include using namespace std; #include using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n,m,q;cin>>n>>m>>q; vcs(n); rep(i,n)cin>>s[i]; dsu d(n*7); vc v(n,vc(0)); rep(i,m){ int a,b;cin>>a>>b; a--;b--; v[a].pb(b);v[b].pb(a); rep(j,7)if(s[a][j]=='1'&&s[b][j]=='1')d.merge(7*a+j,7*b+j); } rep(i,n)rep(j,7){ int nj=(j+1)%7; if(s[i][j]=='1'&&s[i][nj]=='1')d.merge(i*7+j,i*7+nj); } rep(z,q){ int t,x,y;cin>>t>>x>>y; x--; y--; if(t==1){ s[x][y]='1'; int ny=(y+1)%7; if(s[x][ny]=='1')d.merge(7*x+y,7*x+ny); ny=(y-1+7)%7; if(s[x][ny]=='1')d.merge(7*x+y,7*x+ny); for(auto au:v[x])if(s[au][y]=='1')d.merge(7*x+y,7*au+y); } else{ cout<