class Unionfind: def __init__(self,n): self.uf = [-1]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def union(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self,x): x = self.find(x) return -self.uf[x] n,m,q = map(int,input().split()) S = [list(input()) for i in range(n)] e = [[] for i in range(n)] for i in range(m): a,b = map(int,input().split()) a -= 1 b -= 1 e[a].append(b) e[b].append(a) Q = [tuple(map(int,input().split())) for i in range(q)] uf = Unionfind(n*7) used = [0]*n from collections import deque def connect(x,y): for i in range(7): if S[x][i] == "1" and S[y][i] == "1": uf.union(7*x+i,7*y+i) for i in range(n): if used[i]: continue q = deque([i]) while q: now = q.popleft() for nex in e[now]: connect(now,nex) used[nex] = 1 q.append(nex) for i,j,k in Q: if i == 2: print(uf.size(0)) else: S[j][k-1] = "1" for nex in e[j]: connect(nex,j)