class UnionFindNode: def __init__(self, group_id, parent=None, value=None): self.group_id_ = group_id self.parent_ = parent self.value = value self.rank_ = 1 self.member_num_ = 1 def is_root(self): return not self.parent_ def root(self): parent = self while not parent.is_root(): parent = parent.parent_ self.parent_ = parent return parent def find(self): root = self.root() return root.group_id_ def rank(self): root = self.root() return root.rank_ def unite(self, unite_node): root = self.root() unite_root = unite_node.root() if root.group_id_ != unite_root.group_id_: if root.rank() > unite_root.rank(): n_root, child = root, unite_root else: n_root, child = unite_root, root child.parent_ = n_root n_root.rank_ = max(n_root.rank_, child.rank_ + 1) n_root.member_num_ = n_root.member_num_ + child.member_num_ import sys;input=sys.stdin.readline N, M, Q = map(int, input().split()) nodes = [UnionFindNode(i) for i in range(N*7)] ss = [] for i in range(N): s = input().strip() ss.append([c for c in s]) n = i*7 for j in range(7): if s[j] == "1" and s[(j+1)%7] == "1": nodes[n+j].unite(nodes[n+(j+1)%7]) G = [set() for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) u-=1;v-=1; G[u].add(v) G[v].add(u) for i in range(7): if ss[u][i] == "1" and ss[v][i] == "1": nodes[u*7+i].unite(nodes[v*7+i]) for _ in range(Q): a, b, c = map(int, input().split()) if a == 2: print(nodes[(b-1)*7].root().member_num_) else: b-=1 c-=1 ss[b][c] = "1" if ss[b][(c+1)%7] == "1": nodes[b*7+c].unite(nodes[b*7+(c+1)%7]) if ss[b][(c-1)%7] == "1": nodes[b*7+c].unite(nodes[b*7+(c-1)%7]) for u in G[b]: if ss[u][c] == "1": nodes[b*7+c].unite(nodes[u*7+c])