import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto Q = s[2]; auto G = new int[][](N); auto colors = new bool[][](N, 7); auto uf = new UnionFind(N * 7); foreach (i; 0..N) { auto t = readln.chomp; foreach (j; 0..7) if (t[j] == '1') colors[i][j] = true; foreach (j; 0..7) if (colors[i][j] && colors[i][(j+1)%7]) uf.unite(i + N * j, i + (N * ((j + 1) % 7))); } foreach (_; 0..M) { s = readln.split.map!(to!int); auto u = s[0] - 1; auto v = s[1] - 1; G[u] ~= v; G[v] ~= u; foreach (i; 0..7) if (colors[u][i] && colors[v][i]) uf.unite(u + N * i, v + N * i); } foreach (_; 0..Q) { auto q = readln.split.map!(to!int); auto x = q[1] - 1; auto y = q[2] - 1; if (q[0] == 1) { colors[x][y] = true; foreach (v; G[x]) if (colors[v][y]) uf.unite(x + N * y, v + N * y); int prev = (y + 6) % 7; int next = (y + 1) % 7; if (colors[x][prev]) uf.unite(x + N * y, x + N * prev); if (colors[x][next]) uf.unite(x + N * y, x + N * next); } else { uf.size[uf.find(x)].writeln; } } } class UnionFind { import std.algorithm : swap; int n; int[] table; int[] size; this(int n) { this.n = n; table = new int[](n); table[] = -1; size = new int[](n); size[] = 1; } int find(int x) { return table[x] < 0 ? x : (table[x] = find(table[x])); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (table[x] > table[y]) swap(x, y); table[x] += table[y]; table[y] = x; size[x] += size[y]; } bool same(int x, int y) { return find(x) == find(y); } }