import sys read=sys.stdin.read readlines=sys.stdin.readlines input=sys.stdin.readline N, M, Q = map(int, input().split()) S = [list(map(int, input().rstrip())) for _ in [0]*N] class UnionFind: def __init__(self, n=0): self.d = [-1]*n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False if x > y: x, y = y, x self.d[x] += self.d[y] self.d[y] = x self.u -= 1 return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.d[self.root(x)] def num_union(self): return self.u uf = UnionFind(N*7) for i in range(N): for c in range(7): if S[i][c] and S[i][c-1]: uf.unite(i*7+c, i*7+(c-1)%7) G = [[] for _ in range(N)] for _ in [0]*M: a, b = map(int, input().split()) a -= 1; b -= 1 G[a].append(b) G[b].append(a) for c in range(7): if S[a][c] == 0 or S[b][c] == 0: continue uf.unite(a*7+c, b*7+c) ans = [] for line in readlines(): k, x, c = map(int, line.split()) x -= 1; c -= 1 if k == 1: S[x][c] = 1 for v in G[x]: if S[v][c] == 0: continue uf.unite(x*7+c, v*7+c) if S[x][(c+1)%7]: uf.unite(x*7+c, x*7+(c+1)%7) if S[x][c-1]: uf.unite(x*7+c, x*7+(c-1)%7) else: ans.append(uf.size(x*7)) print('\n'.join(map(str, ans)))