#include using namespace std; int main() { ios::sync_with_stdio(false); int N, M, Q; { cin >> N >> M >> Q; } vector on(7 * N); { for (int i = 0; i < N; ++i) { string S; { cin >> S; } for (int j = 0; j < 7; ++j) { on[7 * i + j] = S[j] == '1'; } } } vector> G(N); { for (int i = 0; i < M; ++i) { int U, V; { cin >> U >> V; --U, --V; } G[U].push_back(V); G[V].push_back(U); } } vector sz(N * 7, 1); vector fa(N * 7); { iota(fa.begin(), fa.end(), 0); } function find = [&](int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }; function unite = [&](int x, int y) { int fx = find(x); int fy = find(y); if (fx == fy) return; sz[fx] += sz[fy]; fa[fy] = fx; }; auto update = [&](int X, int Y) { if (on[X * 7 + (Y + 1) % 7]) unite(X * 7 + (Y + 1) % 7, X * 7 + Y); if (on[X * 7 + (Y + 6) % 7]) unite(X * 7 + (Y + 6) % 7, X * 7 + Y); for (int v : G[X]) if (on[v * 7 + Y]) unite(v * 7 + Y, X * 7 + Y); }; for (int u = 0; u < N; ++u) { for (int c = 0; c < 7; ++c) { if (on[u * 7 + c]) update(u, c); } } while (Q--) { int P, X, Y; { cin >> P >> X >> Y; --X, --Y; } if (P == 1) { on[X * 7 + Y] = 1; update(X, Y); } else { cout << sz[find(X * 7)] << '\n'; } } }