import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n def root(self, x): r = x while not self.par[r]<0: r = self.par[r] t = x while t!=r: tmp = t t = self.par[t] self.par[tmp] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx==ry: return if self.rank[rx]<=self.rank[ry]: self.par[ry] += self.par[rx] self.par[rx] = ry if self.rank[rx]==self.rank[ry]: self.rank[ry] += 1 else: self.par[rx] += self.par[ry] self.par[ry] = rx def is_same(self, x, y): return self.root(x)==self.root(y) def count(self, x): return -self.par[self.root(x)] N, M, Q = map(int, input().split()) s = [list(input()[:-1]) for _ in range(N)] uf = Unionfind(7*N) for i in range(N): for j in range(7): if s[i][j]=='1' and s[i][(j+1)%7]=='1': uf.unite(7*i+j, 7*i+(j+1)%7) G = [[] for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) G[u-1].append(v-1) G[v-1].append(u-1) for i in range(7): if s[u-1][i]=='1' and s[v-1][i]=='1': uf.unite(7*(u-1)+i, 7*(v-1)+i) for _ in range(Q): com = tuple(map(int, input().split())) if com[0]==1: x, y = com[1]-1, com[2]-1 s[x][y] = '1' if s[x][(y-1)%7]=='1': uf.unite(7*x+(y-1)%7, 7*x+y) if s[x][(y+1)%7]=='1': uf.unite(7*x+(y+1)%7, 7*x+y) for nx in G[x]: if s[nx][y]=='1': uf.unite(7*x+y, 7*nx+y) else: print(uf.count(7*(com[1]-1)))