mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, Q = map(int, input().split()) S = [] for _ in range(N): S.append(list(input().rstrip('\n'))) E = [] adj = [[] for _ in range(N+1)] for _ in range(M): u, v = map(int, input().split()) E.append((u, v)) adj[u].append(v) adj[v].append(u) UF = UnionFind(N * 7) for i in range(N): si = S[i] for j in range(6): if si[j] == si[j+1] == "1": UF.unite(i+1 + j*N, i+1 + (j+1)*N) if si[0] == si[-1] == "1": UF.unite(i+1, i+1 + 6*N) for u, v in E: su = S[u-1] sv = S[v-1] for j in range(7): if su[j] == sv[j] == "1": UF.unite(u + j*N, v + j*N) for _ in range(Q): t, x, y = map(int, input().split()) if t == 1: # self city S[x-1][y-1] = "1" prev = y-1 if y > 1 else 7 nxt = y+1 if y < 7 else 1 if S[x-1][prev-1] == "1": UF.unite(x + (y-1)*N, x + (prev-1)*N) if S[x-1][nxt-1] == "1": UF.unite(x + (y - 1) * N, x + (nxt - 1) * N) # adj for z in adj[x]: if S[z-1][y-1] == "1": UF.unite(x + (y-1)*N, z + (y-1)*N) else: print(UF.size(1)) if __name__ == '__main__': main()