#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define inf 1e18 using namespace std; typedef long long llint; typedef pair P; struct UnionFind{ int size; vector parent; vector num; UnionFind(){} UnionFind(int size){ this->size = size; parent.resize(size+1); num.resize(size+1); init(); } void init(){ for(int i = 0; i <= size; i++) parent[i] = i, num[i] = 1; } int root(int i){ if(parent[i] == i) return i; return parent[i] = root(parent[i]); } bool same(int i, int j){ return root(i) == root(j); } void unite(int i, int j){ int root_i = root(i), root_j = root(j); if(root_i == root_j) return; num[root_j] += num[root_i]; parent[root_i] = root_j; } }; llint n, m, Q; string s[100005]; vector G[100005]; UnionFind uf(1000005); int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> Q; for(int i = 1; i <= n; i++) cin >> s[i]; llint u, v; for(int i = 1; i <= m; i++){ cin >> u >> v; G[u].push_back(v); G[v].push_back(u); for(int i = 0; i < 7; i++){ if(s[u][i]%2 && s[v][i]%2) uf.unite(i*n+u, i*n+v); } } for(int i = 1; i <= n; i++){ for(int j = 0; j < 7; j++){ if(s[i][j]%2 && s[i][(j+1)%7]%2) uf.unite(j*n+i, (j+1)%7*n+i); } } llint t, x, y; for(int q = 0; q < Q; q++){ cin >> t >> x >> y; y--; if(t == 1){ s[x][y] = '1'; for(int j = 0; j < 7; j++){ if(s[x][j]%2 && s[x][(j+1)%7]%2) uf.unite(j*n+x, (j+1)%7*n+x); } for(int i = 0; i < G[x].size(); i++){ llint nx = G[x][i]; if(s[nx][y]%2) uf.unite(y*n+x, y*n+nx); } } else cout << uf.num[uf.root(x)] << endl; } return 0; }