#include #include #include using namespace std; struct UnionFind { vector data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; int main() { int n, m, q; cin >> n >> m >> q; UnionFind uf(n * 7); vector s(n); for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < 7; j++) { if (s[i][j] == '1' && s[i][(j + 1) % 7] == '1') { uf.unite(j * n + i, ((j + 1) % 7) * n + i); } } } vector> graph(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v, u--, v--; graph[u].push_back(v), graph[v].push_back(u); for (int j = 0; j < 7; j++) { if (s[u][j] == '1' && s[v][j] == '1') { uf.unite(j * n + u, j * n + v); } } } for (int i = 0; i < q; i++) { int query, x, y; cin >> query >> x >> y, x--, y--; if (query == 1) { s[x][y] = '1'; for (int j = 0; j < 7; j++) { if (s[x][j] == '1' && s[x][(j + 1) % 7] == '1') { uf.unite(j * n + x, ((j + 1) % 7) * n + x); } } for (auto to:graph[x]) { for (int j = 0; j < 7; j++) { if (s[x][j] == '1' && s[to][j] == '1') { uf.unite(j * n + x, j * n + to); } } } } else { cout << uf.size(x) << "\n"; } } cout << flush; return 0; }