#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); class UFT { int n; int cnt; // number of connected components vector par; vector rank; vector sz; // size of each component public: UFT(int n) : n(n), cnt(n), par(n), rank(n), sz(n) { for (int i = 0; i < n; i++) { par[i] = i; sz[i] = 1; } } int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; --cnt; if (rank[x] < rank[y]) { par[x] = y; sz[y] += sz[x]; } else { par[y] = x; sz[x] += sz[y]; if (rank[x] == rank[y]) ++rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int compCnt() { return cnt; } int size(int x) { return sz[find(x)]; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; UFT tree(7 * n); vector color(n); REP (i, n) { cin >> color[i]; REP (j, 7) { int k = (j + 1) % 7; if (color[i][j] == '1' && color[i][k] == '1') { tree.unite(7*i+j, 7*i+k); } } } vector > edges(n); REP (i, m) { int u, v; cin >> u >> v; --u, --v; edges[u].push_back(v); edges[v].push_back(u); REP (j, 7) { if (color[u][j] == '1' && color[v][j] == '1') { tree.unite(7*u+j, 7*v+j); } } } REP (_, q) { int t, x, y; cin >> t >> x >> y; --x, --y; if (t == 1) { if (color[x][(y+1)%7] == '1') tree.unite(7*x+y, 7*x+(y+1)%7); if (color[x][(y+6)%7] == '1') tree.unite(7*x+y, 7*x+(y+6)%7); for (int v: edges[x]) { if (color[v][y] == '1') tree.unite(7*x+y, 7*v+y); } } else { cout << tree.size(7*x) << endl; } } return 0; }