#include using namespace std; #include using namespace atcoder; using ll= long long; using ld= long double; using pll= pair; using vi= vector; using vl= vector; using vd= vector; using vs= vector; using vb= vector; using vpll= vector; using vvi= vector; using vvl= vector; using vvd= vector; using vvs= vector; using vvb= vector; using vvpll= vector; using mint= modint1000000007; // using mint = modint998244353; constexpr ll mod= 1e9 + 7; // constexpr ll mod= 998244353; #define ALL(x) (x).begin(), (x).end() #define _overload(_1, _2, _3, name, ...) name #define REPBASE(i, a, b) for(ll(i)= (a); (i) < (b); (i)++) #define RREPBASE(i, a, b) for(ll(i)= (a); (i) >= (b); (i)--) #define REPB(i, n) REPBASE(i, 0, n) #define REPS(i, n) REPBASE(i, 1, n + 1) #define RREP(i, n) RREPBASE(i, n - 1, 0) #define RREPS(i, n) RREPBASE(i, n, 1) #define REP(...) _overload(__VA_ARGS__, REPBASE, REPB)(__VA_ARGS__) #define EACH(x, c) for(auto &x : c) #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()) #define YES(n) ((n) ? "YES" : "NO") #define Yes(n) ((n) ? "Yes" : "No") #define yes(n) ((n) ? "yes" : "no") #define SZ(x) ((ll)(x).size()) #define BIT(n) (1LL << (n)) template inline bool chmax(T &a, const T &b) { if(a < b) { a= b; return 1; } return 0; } template inline bool chmin(T &a, const T &b) { if(b < a) { a= b; return 1; } return 0; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll N,M,Q; cin >> N >> M >> Q; vs C(N); REP(i,N)cin >> C[i]; dsu D(N*7); REP(i,N){ REP(l,7){ if(C[i][l] == '1' && C[i][(l+1) % 7] == '1'){ D.merge(i*7+l,i*7+(l+1)%7); } } } vvl G(N,vl(0)); REP(i,M){ ll pq,qr; cin >> pq >> qr; pq--;qr--; G[pq].eb(qr); G[qr].eb(pq); REP(l,7){ if(C[pq][l] == '1' && C[qr][l] == '1'){ D.merge(pq*7+l,qr*7+l); } } } REP(i,Q){ ll Type; cin >> Type; if(Type == 1){ ll x,y; cin >> x >> y; x--;y--; C[x][y] == '1'; if(C[x][(y+1) % 7] == '1'){ D.merge(x*7+y,x*7+(y+1)%7); } if(C[x][(y+6) % 7] == '1'){ D.merge(x*7+y,x*7+(y+6)%7); } EACH(p,G[x]){ if(C[p][y] == '1'){ D.merge(x*7+y,p*7+y); } } }else{ ll x,y; cin >> x >> y; x--; cout << D.size(7*x) << "\n"; } } }