class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def root(self, v): if self.node[v] < 0: return v st = [] while self.node[v] >= 0: st.append(v) v = self.node[v] for u in st: self.node[u] = v return v def size(self, v): v = self.root(v) return (- self.node[v]) def same(self, u, v): return self.root(u) == self.root(v) def unite(self, u, v): ru = self.root(u) rv = self.root(v) if ru == rv: return du = self.node[ru] dv = self.node[rv] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du n, m, q = map(int, input().split()) used = [[False for _ in range(7)] for _ in range(n)] uf = UnionFind(7 * n) for v in range(n): s = input() for c in range(7): if s[c] == '1': used[v][c] = True for c in range(7): if used[v][c] and used[v][c - 1]: uf.unite(7 * v + c, 7 * v + (c - 1) % 7) g = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 g[u].append(v) g[v].append(u) for c in range(7): if used[u][c] and used[v][c]: uf.unite(7 * u + c, 7 * v + c) ans = [] for _ in range(q): t, x, y = map(int, input().split()) if t == 1: x -= 1 y -= 1 used[x][y] = True u = 7 * x + y if used[x][y - 1]: uf.unite(u, 7 * x + (y - 1) % 7) if used[x][(y + 1) % 7]: uf.unite(u, 7 * x + (y + 1) % 7) for z in g[x]: if used[z][y]: uf.unite(u, 7 * z + y) elif t == 2: x -= 1 ans.append(uf.size(7 * x)) print(*ans, sep='\n')