import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class UnionFind: def __init__(self, N): self.N = N self.par = [-1] * N def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if x > y: x, y = y, x self.par[x] += self.par[y] self.par[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] def roots(self): return [i for i in range(self.N) if self.par[i] < 0] def members(self, x): p = self.find(x) return [i for i in range(self.N) if self.find(i) == p] def h(i, j): return i * 7 + j N, M, Q = map(int, input().split()) S = [[int(c) for c in input()[:-1]] for _ in range(N)] uf = UnionFind(7 * N) A = list(range(7)) B = list(range(1, 7)) + [0] for i in range(N): s = S[i] for a, b in zip(A, B): if s[a] * s[b] > 0: uf.unite(h(i, a), h(i, b)) E = [[] for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 E[u].append(v) E[v].append(u) for j in range(7): if S[u][j] * S[v][j] > 0: uf.unite(h(u, j), h(v, j)) for _ in range(Q): t, x, y = map(int, input().split()) x -= 1 y -= 1 if t == 1: S[x][y] = 1 pre = (y - 1) % 7 nxt = (y + 1) % 7 for j in [pre, nxt]: if S[x][j] > 0: uf.unite(h(x, y), h(x, j)) for d in E[x]: if S[d][y]: uf.unite(h(x, y), h(d, y)) else: print(uf.size(h(x, 0)))