import sys input = sys.stdin.readline class UnionFind: def __init__(self, N): self.par = [-1] * N def find(self, x): r = x while self.par[r] >= 0: r = self.par[r] while x != r: tmp = self.par[x] self.par[x] = r x = tmp return r def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] N, M, Q = map(int, input().split()) s = [list(map(int, input().rstrip())) for _ in range(N)] G = [[] for _ in range(N)] uf = UnionFind(7 * N) for i in range(N): for j in range(7): if s[i][j] and s[i][(j + 1) % 7]: uf.unite(7 * i + j, 7 * i + (j + 1) % 7) for _ in range(M): u, v = map(lambda x: int(x) - 1, input().split()) G[u].append(v) G[v].append(u) for j in range(7): if s[u][j] and s[v][j]: uf.unite(7 * u + j, 7 * v + j) for _ in range(Q): t, x, y = map(int, input().split()) x -= 1 y -= 1 if t == 1: s[x][y] = 1 if s[x][(y - 1) % 7]: uf.unite(7*x + (y - 1) % 7, 7*x + y) if s[x][(y + 1) % 7]: uf.unite(7*x + y, 7*x + (y + 1) % 7) for v in G[x]: if s[v][y]: uf.unite(7*x + y, 7*v + y) else: print(uf.size(7*x))