import sys readline = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(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 union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M, Q = map(int, readline().split()) S = [] for i in range(N): s = list(readline().rstrip("\n")) s = list(map(int, s)) v = 0 for j in range(7): if s[j]: v += 1 << j S.append(v) G = [[] for i in range(N)] for i in range(M): u, v = map(int, readline().split()) u, v = u - 1, v - 1 G[u].append(v) G[v].append(u) U = UnionFind(7 * N) for u in range(N): for y in range(7): if (S[u] >> y) & 1 == 0: continue ym = (y - 1) % 7 if (S[u] >> ym) & 1: U.union(7 * u + y, 7 * u + ym) yp = (y + 1) % 7 if (S[u] >> yp) & 1: U.union(7 * u + y, 7 * u + yp) for v in G[u]: for k in range(7): if (S[u] >> k) & 1 and (S[v] >> k) & 1: U.union(7 * u + k, 7 * v + k) for _ in range(Q): q, u, y = map(int, readline().split()) u, y = u - 1, y - 1 if q == 1: S[u] |= 1 << y ym = (y - 1) % 7 if (S[u] >> ym) & 1: U.union(7 * u + y, 7 * u + ym) yp = (y + 1) % 7 if (S[u] >> yp) & 1: U.union(7 * u + y, 7 * u + yp) for v in G[u]: if (S[u] >> y) & 1 and (S[v] >> y) & 1: U.union(7 * u + y, 7 * v + y) else: print(U.get_size(0))