#include #include #include #include #include #include #include using namespace std; typedef long long ll; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) { } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int n, m, q; string s[100000]; vector G[100000]; int to_idx(int i, int col){ return i*n+col; } UnionFind uf(0); void input(){ cin >> n >> m >> q; uf = UnionFind(n*7); for(int i = 0; i < n; i++) cin >> s[i]; 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); for(int col = 0; col < 7; col++){ if(s[u][col] == '1' && s[v][col] == '1'){ uf.unionSet(to_idx(u, col), to_idx(v, col)); } } } for(int i = 0; i < n; i++){ for(int j = 0; j < 7; j++){ if(s[i][j] == '1' && s[i][(j+1)%7] == '1'){ uf.unionSet(to_idx(i, j), to_idx(i, (j+1)%7)); } } } } void solve(){ int t, x, y; cin >> t >> x >> y; x--; y--; if(t == 1){ int nx = (y+1)%7; int pre = (y+6)%7; s[x][y] = '1'; if(s[x][pre] == '1') uf.unionSet(to_idx(x, pre), to_idx(x, y)); if(s[x][nx] == '1') uf.unionSet(to_idx(x, nx), to_idx(x, y)); for(int to : G[x]){ if(s[to][y] == '1'){ uf.unionSet(to_idx(x, y), to_idx(to, y)); } } }else{ cout << uf.size(to_idx(x, 0)) << endl; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; input(); for(int i = 0; i < q; i++) solve(); }