#include "bits/stdc++.h" using namespace std; //#include "atcoder/all" //using namespace atcoder; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) templateistream&operator >>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateinline void out(T t){cout << t << "\n";} templateinline void out(T t,Ts... ts){cout << t << " ";out(ts...);} templateinline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;} templateinline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;} constexpr int INF = 1e18; struct UF{ vectorpar,sz; void init(int n){ par.resize(n); sz.resize(n); for(int i=0;i> N >> M >> Q; vector s(N); cin >> s; vector> g(N); REP(i, M) { int a, b; cin >> a >> b; --a; --b; g[a].emplace_back(b); g[b].emplace_back(a); } UF uf; uf.init(N * 7); REP(i, N) { REP(j, 7) { if(s[i][j] == '1' && s[i][(j + 1) % 7] == '1') { uf.unite(i * 7 + j, i * 7 + (j + 1) % 7); } } for(auto e: g[i]) { REP(j, 7) { if(s[i][j] == '1' && s[e][j] == '1') uf.unite(i * 7 + j, e * 7 + j); } } } REP(i, Q) { int t, x, y; cin >> t >> x >> y; --x; --y; if(t == 1) { s[x][y] = '1'; if(s[x][(y + 1) % 7] == '1') uf.unite(x * 7 + y, x * 7 + (y + 1) % 7); if(s[x][(y - 1 + 7) % 7] == '1') uf.unite(x * 7 + y, x * 7 + (y - 1 + 7) % 7); for(auto e: g[x]) { if(s[e][y] == '1') uf.unite(x * 7 + y, e * 7 + y); } } else { out(uf.size(x * 7)); } } }