// g++ A.cpp -std=c++14 -I . && ./a.out #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, a, b) for (int i = a; i < (int)(b); i++) #define all(v) v.begin(), v.end() using ll = long long; const ll INF = 1e18; // 変数定義 int N, M, Q, a, b, c, d, e, x, y, t, T, total, cnt, ans; struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } private: int _n; // root node: -1 * component size // otherwise: parent vector parent_or_size; }; int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); cin >> N >> M >> Q; dsu uf(N * 7); vector S(N); rep(i, N) { cin >> S[i]; rep(j, 7) { if (S[i][j] == '1' && S[i][(j + 1) % 7] == '1') { uf.merge(i * 7 + j, i * 7 + (j + 1) % 7); // cout << i * 7 + j << ' ' << i * 7 + (j + 1) % 7 << '\n'; } } } vector> edge(N); rep(i, M) { cin >> x >> y; x--; y--; edge[x].push_back(y); edge[y].push_back(x); rep(j, 7) { if (S[x][j] == '1' && S[y][j] == '1') { uf.merge(x * 7 + j, y * 7 + j); // cout << x * 7 + j << ' ' << y * 7 + j << '\n'; } } } rep(i, Q) { cin >> t >> a >> b; a--; b--; if (t == 1) { S[a][b] = '1'; if (S[a][abs((b - 1) % 7)] == '1') { uf.merge(a * 7 + abs((b - 1) % 7), a * 7 + b); // cout << a * 7 + abs((b - 1) % 7) << ' ' << a * 7 + b << '\n'; } if (S[a][(b + 1) % 7] == '1') { uf.merge(a * 7 + (b + 1) % 7, a * 7 + b); // cout << a * 7 + ((b + 1) % 7) << ' ' << a * 7 + b << '\n'; } for (auto v : edge[a]) { if (S[v][b] == '1') { uf.merge(a * 7 + b, v * 7 + b); // cout << a * 7 + b << ' ' << v * 7 + b << '\n'; } } } else { cout << uf.size(a * 7) << '\n'; } } return 0; }