# coding:UTF-8 import sys MOD = 10 ** 9 + 7 INF = float('inf') # ユニオンファインド木 class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n self.rank = [0] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return elif self.rank[x] > self.rank[y]: self.parents[x] += self.parents[y] self.parents[y] = x else: self.parents[y] += self.parents[x] self.parents[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): d = {r: {r} for r in self.roots()} for i in range(self.n): d[self.find(i)].add(i) return d def __str__(self): d = self.all_group_members() return '\n'.join('{}: {}'.format(r, d[r]) for r in d.keys()) N, M, Q = list(map(int, input().split())) # スペース区切り連続数字 St = [input() for _ in range(N)] # 文字 UV = [list(map(int, input().split())) for _ in range(M)] # スペース区切り連続数字(行列) Query = [list(map(int, input().split())) for _ in range(Q)] # スペース区切り連続文字 S = [] for i in range(N): S.append([]) for c in range(7): S[i].append(int(St[i][c])) E = [[] for i in range(N)] for u, v in UV: E[u-1].append(v-1) E[v-1].append(u-1) uf = UnionFind(7*N) for i in range(N): s = S[i] for c in range(7): if c == 6: if S[i][6] == 1 and S[i][0] == 1: uf.union(6 * N + i, i) else: if S[i][c] == 1 and S[i][c+1] == 1: uf.union(c * N + i, (c+1) * N + i) for u, v in UV: for c in range(7): if S[u-1][c] == 1 and S[v-1][c] == 1: uf.union(c * N + (u - 1), c * N + (v - 1)) for q in Query: if q[0] == 1: i = q[1] - 1 c = q[2] - 1 if c == 0: S[i][0] = 1 if S[i][6] == 1 and S[i][0] == 1: uf.union(6 * N + i, i) if S[i][0] == 1 and S[i][1] == 1: uf.union(N + i, i) elif c == 6: S[i][6] = 1 if S[i][6] == 1 and S[i][0] == 1: uf.union(6 * N + i, i) if S[i][5] == 1 and S[i][6] == 1: uf.union(5 * N + i, 6 * N + i) else: S[i][c] = 1 if S[i][c] == 1 and S[i][c-1] == 1: uf.union(c * N + i, (c-1) * N + i) if S[i][c] == 1 and S[i][c+1] == 1: uf.union(c * N + i, (c+1) * N + i) for e in E[i]: if S[i][c] == 1 and S[e][c] == 1: uf.union(c * N + i, c * N + e) elif q[0] == 2: i = q[1] - 1 res = uf.size(i) print("{}".format(res))