#Union-Find class UnionFind(): def __init__(self, n): self.n = n self.par = list(range(self.n)) self.rank = [1] * n self.count = n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): p = self.find(x) q = self.find(y) if p == q: return None if p > q: p, q = q, p self.rank[p] += self.rank[q] self.par[q] = p self.count -= 1 def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return self.rank[x] def count(self): return self.count n, m, q = map(int, input().split()) s = [list(input()) for i in range(n)] UF = UnionFind(n * 7) for i in range(n): for j in range(7): if s[i][j] == "1" and s[i][(j + 1) % 7] == "1": UF.unite(i * 7 + j, i * 7 + (j + 1) % 7) edges = [[] for i in range(n)] for i in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 edges[x].append(y) edges[y].append(x) for j in range(7): if s[x][j] == "1" and s[y][j] == "1": UF.unite(x * 7 + j, y * 7 + j) for i in range(q): qu, a, b = map(int, input().split()) a -= 1 b -= 1 if qu == 1: s[a][b] = "1" if s[a][(b - 1) % 7] == "1": UF.unite(a * 7 + (b - 1) % 7, a * 7 + b) if s[a][(b + 1) % 7] == "1": UF.unite(a * 7 + (b + 1) % 7, a * 7 + b) for u in edges[a]: if s[u][b] == "1": UF.unite(a * 7 + b, u * 7 + b) else: print(UF.size(a * 7))