#include using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector #define mat vector > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef long double ld; typedef complex comp; const ll INF=1e9+7; const ll inf=INF*INF; const ll MOD=1e9+7; const ll mod=MOD; const int MAX=200010; //Union-Find木 struct UnionFind { vector< int > data; UnionFind() = default; explicit UnionFind(size_t sz) : data(sz, -1) {} bool unite(int x, int y) { x = find(x), y = find(y); if(x == y) return false; if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } int find(int k) { if(data[k] < 0) return (k); return data[k] = find(data[k]); } int size(int k) { return -data[find(k)]; } bool same(int x, int y) { return find(x) == find(y); } }; signed main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,m,q;cin>>n>>m>>q; UnionFind uf(n*7); vectors(n); rep(i,n)cin>>s[i]; vector >G(n); rep(i,m){ ll u,v;cin>>u>>v; u--;v--; G[u].pb(v); G[v].pb(u); rep(col,7){ if(s[u][col]=='1'&&s[v][col]=='1')uf.unite(7*u+col,7*v+col); } } rep(i,n){ rep(col,7){ if(s[i][col]=='1'&&s[i][(col+1)%7]=='1'){ uf.unite(i*7+col,i*7+(col+1)%7); } } } while(q--){ ll t;cin>>t; if(t==1){ ll x,y;cin>>x>>y; x--; y--; s[x][y]='1'; if(s[x][(y+6)%7]=='1'){ uf.unite(x*7+y,x*7+(y+6)%7); } if(s[x][(y+1)%7]=='1'){ uf.unite(x*7+y,x*7+(y+1)%7); } for(auto e:G[x]){ if(s[e][y]=='1'){ uf.unite(x*7+y,e*7+y); } } }else{ ll x,y;cin>>x>>y; x--;y--; cout<