#include using namespace std; using ll = long long; class UnionFind{ private: vector data; public: UnionFind(int n) : data(n,-1) {} int root(int i) { return data[i] < 0 ? i : data[i] = root(data[i]); } int size(int i) { return -data[root(i)]; } bool same(int x, int y) {return root(x) == root(y); } bool connected() {return size(0) == (int)data.size(); } bool unit(int i,int j){ i = root(i); j = root(j); if(size(j) > size(i))swap(j, i); if(i != j){ data[i] += data[j]; data[j] = i; } return i != j; } }; int N, M, Q; int id(int city, int color) { return city * 7 + color; } int main() { cin >> N >> M >> Q; vector s(N); vector> hen(N); for(auto &i: s) {cin >> i; for(auto &j : i) j -= '0';}; UnionFind tree(7 * N); for(int i = 0; i < N; i++) { for(int j = 0; j < 7; j++)if(s[i][j] && s[i][(j + 1) % 7])tree.unit(id(i, j), id(i, (j + 1) % 7)); } for(int i = 0; i < M; i++) {int a, b; cin >> a >> b; a--, b--; hen[a].push_back(b), hen[b].push_back(a); for(int j = 0; j < 7; j++) { if(s[a][j] && s[b][j]) tree.unit(id(a, j), id(b, j)); } } for(int i = 0; i < Q; i++) { int t; cin >> t; if(t == 1) { int x, y; cin >> x >> y; x--, y--; auto& st = s[x]; st[y] = 1; if(st[(y + 1) % 7])tree.unit(id(x, y), id(x, (y + 1) % 7)); if(st[(y - 1 + 7) % 7])tree.unit(id(x, y), id(x, (y - 1 + 7) % 7)); for(auto nxt : hen[x]) { if(s[nxt][y]) tree.unit(id(x, y), id(nxt, y)); } } else { int x, y; cin >> x >> y; x--; cout << tree.size(id(x, 0)) << '\n'; } } }