#include #define rep(i, n) for (int i = 0; i < (ll)(n); i++) using namespace std; typedef long long ll; const int MAX_N = 700000; int par[MAX_N]; int rnk[MAX_N]; int siz[MAX_N]; void init(int n) { rep(i,n) { par[i] = i; rnk[i] = 0; siz[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; int s = siz[x] + siz[y]; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } siz[find(x)] = s; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } int main() { ll N, M, Q; cin >> N >> M >> Q; vector s(N); rep(i, N) cin >> s[i]; vector u(M), v(M), a(Q), b(Q), c(Q); vector> edge(N); rep(i, M) { cin >> u[i] >> v[i]; u[i]--; v[i]--; edge[u[i]].push_back(v[i]); edge[v[i]].push_back(u[i]); } rep(i, Q) { cin >> a[i] >> b[i] >> c[i]; b[i]--; c[i]--; } init(N * 7); rep(i, M) { rep(j, 7) { if (s[u[i]][j] == '1' && s[v[i]][j] == '1') { unite(u[i] * 7 + j, v[i] * 7 + j); } } } rep(i, N) { rep(j, 7) { if (s[i][j] == '1' && s[i][(j + 1) % 7] == '1') { unite(i * 7 + j, i * 7 + (j + 1) % 7); } } } rep(i, Q) { if (a[i] == 1) { s[b[i]][c[i]] = '1'; if (s[b[i]][(c[i] + 1) % 7] == '1') unite(b[i] * 7 + c[i], b[i] * 7 + ((c[i] + 1) % 7)); if (s[b[i]][(c[i] + 6) % 7] == '1') unite(b[i] * 7 + c[i], b[i] * 7 + ((c[i] + 6) % 7)); rep(j, edge[b[i]].size()) { ll x = edge[b[i]][j]; if (s[x][c[i]] == '1') unite(b[i] * 7 + c[i], x * 7 + c[i]); } } else { cout << size(b[i] * 7) << "\n"; } } }