// 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; 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() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M >> Q; disjoint_set 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 (int 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.sizeOf(a * 7) << '\n'; } } return 0; }