#include #include using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair plint; typedef pair pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define endk '\n' templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } const lint MOD = 1e9 + 7, INF = 1e18; lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 }; typedef pair Pa; typedef pair tlint; struct edge { lint cost; lint u, v; }; template< typename T > class UnionFind { public: vector par; // 各元の親を表す配列 vector siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(T sz_) : par(sz_), siz(sz_, 1ll) { for (T i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(T sz_) { par.resize(sz_); siz.assign(sz_, 1ll); // resize だとなぜか初期化されなかった for (T i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find T root(T x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(T x, T y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(T x, T y) { // 連結判定 return root(x) == root(y); } T size(T x) { // 素集合のサイズ return siz[root(x)]; } }; lint N, M, Q, a, b; vector to[100000]; lint color[100000][7]; int main() { cin >> N >> M >> Q; UnionFind tree(N * 7); REP(i, N) { string s; lint cnt = 0; cin >> s; REP(j, 7) { color[i][j] = s[j] - '0'; cnt += (s[j] - '0'); } REP(j, 7) { if (color[i][j] == 1 && color[i][(j + 1) % 7] == 1) { tree.merge(j * N + i, ((j + 1) % 7) * N + i); } } } REP(i, M) { cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); REP(j, 7) { if (color[a][j] == 1 && color[b][j] == 1) { tree.merge(j * N + a, j * N + b); } } } vector ans; REP(i, Q) { lint c, x, y; cin >> c >> x >> y; x--; y--; if (c == 1) { color[x][y] = 1; REP(j, 7) { if (color[x][j] == 1 && color[x][(j + 1) % 7] == 1) { tree.merge(j * N + x, ((j + 1) % 7) * N + x); } } for (lint nxt : to[x]) { if (color[nxt][y] == 1) { tree.merge(y* N + x, y* N + nxt); } } } else { ans.push_back(tree.size(x)); } } REP(i, SZ(ans)) { cout << ans[i] << endk; } }