#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct dsu { vector V; vector Z; dsu(int n) { V.resize(n); Z.assign(n, 1); rep(i, n) V[i] = i; } int root(int a) { if (V[a] == a) return a; return V[a] = root(V[a]); } void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; V[u] = v; Z[v] += Z[u]; } int size(int a) { return Z[root(a)]; } }; int N, M, Q; bool X[100000][7]; vector E[100000]; int main() { cin >> N >> M >> Q; dsu G(N * 7); rep(i, N) rep(x, 7) { char c; cin >> c; X[i][x] = (c == '1'); } rep(i, N) rep(x, 7) { if (X[i][x]) if (X[i][(x + 1) % 7]) G.unite(i * 7 + x, i * 7 + (x + 1) % 7); } rep(i, M) { int u, v; cin >> u >> v; u--; v--; rep(x, 7) if (X[u][x]) if (X[v][x]) G.unite(u * 7 + x, v * 7 + x); E[u].push_back(v); E[v].push_back(u); } rep(q,Q){ int c; cin >> c; if (c == 1) { int x, y; cin >> x >> y; x--; y--; X[x][y] = true; if (X[x][(y + 1) % 7]) G.unite(x * 7 + y, x * 7 + (y + 1) % 7); if (X[x][(y + 6) % 7]) G.unite(x * 7 + y, x * 7 + (y + 6) % 7); for (int e : E[x]) { if (X[e][y]) G.unite(x * 7 + y, e * 7 + y); } } if (c == 2) { int x, z; cin >> x >> z; x--; cout << G.size(x * 7) << endl; } } return 0; }