#include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = int64_t; #define rep(i, j, n) for (int i = j; i < (n); ++i) #define rrep(i, j, n) for (int i = (n)-1; j <= i; --i) template std::ostream &operator<<(std::ostream &os, std::vector &a) { os << "{"; for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i]; return os << "}"; } [[maybe_unused]] constexpr ll MOD = 1000000007; [[maybe_unused]] constexpr int INF = 0x3f3f3f3f; [[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL; class disjoint_set { public: disjoint_set(int n) : par(n, -1) {} void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; } bool same(int x, int y) { return root(x) == root(y); } int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } int sizeOf(int x) { return -par[root(x)]; } private: vector par; }; int main() { int n, m, q; cin >> n >> m >> q; // 頂点iのj色はi * 7 + jで vector s(n); vector> g(n); disjoint_set ds(n * 7); rep(i, 0, n) { cin >> s[i]; rep(j, 0, 7) if (s[i][j] == '1' && s[i][(j + 1) % 7] == '1') ds.merge(i * 7 + j, i * 7 + (j + 1) % 7); } rep(i, 0, m) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); rep(j, 0, 7) if (s[u][j] == '1' && s[v][j] == '1') ds.merge(u * 7 + j, v * 7 + j); } rep(i, 0, q) { int t, x, y; cin >> t >> x >> y; --x, --y; if (t == 1) { s[x][y] = '1'; rep(j, 0, 7) if (s[x][j] == '1' && s[x][(j + 1) % 7] == '1') ds.merge(x * 7 + j, x * 7 + (j + 1) % 7); for (int nx : g[x]) if (s[nx][y] == '1') ds.merge(x * 7 + y, nx * 7 + y); } else cout << ds.sizeOf(x * 7) << '\n'; } return 0; }