#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MAX_V = 100001; const int MAX_N = 1000000; vector parent; vector _rank; vector _size; class UnionFind { public: UnionFind(int n) { for (int i = 0; i < n; ++i) { parent.push_back(i); _rank.push_back(0); _size.push_back(1); } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (_rank[x] < _rank[y]) { parent[x] = y; _size[y] += _size[x]; } else { parent[y] = x; _size[x] += _size[y]; if (_rank[x] == _rank[y]) ++_rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; int calcId(int v, int color) { return MAX_V * color + v; } int S[MAX_V]; vector E[MAX_V]; UnionFind uf(MAX_N); void connect(int u, int v) { for (int c = 0; c < 7; ++c) { if ((S[u] >> c & 1) == 0) continue; if ((S[v] >> c & 1) == 0) continue; int id1 = calcId(u, c); int id2 = calcId(v, c); uf.unite(id1, id2); } } int main() { int N, M, Q; cin >> N >> M >> Q; for (int i = 0; i < N; ++i) { string s; cin >> s; int mask = 0; for (int c = 0; c < 7; ++c) { if (s[c] == '0') continue; mask |= (1 << c); int id = calcId(i, c); int bc = (c + 6) % 7; int ac = (c + 1) % 7; if (s[bc] == '1') { int bid = calcId(i, bc); uf.unite(id, bid); } if (s[ac] == '1') { int aid = calcId(i, ac); uf.unite(id, aid); } } S[i] = mask; } for (int i = 0; i < M; ++i) { int u, v; cin >> u >> v; u--; v--; E[u].push_back(v); E[v].push_back(u); connect(u, v); } int t, x, y; for (int i = 0; i < Q; ++i) { cin >> t >> x >> y; --x; if (t == 1) { int c = y - 1; int id = calcId(x, c); S[x] |= 1 << c; int bc = (c + 6) % 7; int ac = (c + 1) % 7; if (S[x] >> bc & 1) { int bid = calcId(x, bc); uf.unite(id, bid); } if (S[x] >> ac & 1) { int aid = calcId(x, ac); uf.unite(id, aid); } for (int i = 0; i < E[x].size(); ++i) { int z = E[x][i]; connect(x, z); } } else { int id = calcId(x, 0); cout << uf.size(id) << endl; } } return 0; }