#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;} #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << (x) << endl; class UnionFind{ private: vec<int> p,s; int cnt; public: UnionFind(){} UnionFind(int N):cnt(N),s(N,1),p(N){ iota(p.begin(),p.end(),0); } int find(int x){ if(p[x]==x) return x; else return p[x] = find(p[x]); } void unite(int x,int y){ x = find(x); y = find(y); if(x==y) return; if(s[x]>s[y]) swap(x,y); p[x] = y; s[y] += s[x]; cnt--; } bool is_same_set(int x,int y) {return find(x)==find(y);} int size(int x) {return s[find(x)];} int compnents_number(){return cnt;} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M,Q; cin >> N >> M >> Q; UnionFind uf(7*N); auto node = [&](int v,int c){ return c*N+v; }; vec<string> S(N); auto update_color = [&](int i){ for(int j=0;j<7;j++){ for(int k=1;k<=1;k+=2){ int c = (j+k+7)%7; if(S[i][j]=='1' && S[i][c]=='1') uf.unite(node(i,j),node(i,c)); } } }; for(int i=0;i<N;i++){ cin >> S[i]; update_color(i); } vvec<int> g(N); for(int i=0;i<M;i++){ int a,b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); for(int j=0;j<7;j++) if(S[a][j]=='1' && S[b][j]=='1') uf.unite(node(a,j),node(b,j)); } auto update = [&](int v,int c){ S[v][c] = '1'; update_color(v); for(auto& u:g[v]) if(S[v][c]=='1' && S[u][c]=='1') uf.unite(node(v,c),node(u,c)); }; while(Q--){ int t,x,y; cin >> t >> x >> y; x--,y--; if(t==1) update(x,y); else cout << uf.size(node(x,0)) << "\n"; } }