class UnionFind(): def __init__(self,n): self.n=n self.root=[-1]*(n+1) self.rank=[0]*(n+1) def FindRoot(self,x): if self.root[x]<0: return x else: self.root[x]=self.FindRoot(self.root[x]) return self.root[x] def Unite(self,x,y): x=self.FindRoot(x) y=self.FindRoot(y) if x==y: return else: if self.rank[x]>self.rank[y]: self.root[x]+=self.root[y] self.root[y]=x elif self.rank[x]<=self.rank[y]: self.root[y]+=self.root[x] self.root[x]=y if self.rank[x]==self.rank[y]: self.rank[y]+=1 def isSameGroup(self,x,y): return self.FindRoot(x)==self.FindRoot(y) def Count(self,x): return -self.root[self.FindRoot(x)] n,m,q=map(int,input().split()) colors=[list(input()) for _ in range(n)] g=[[] for _ in range(n)] for _ in range(m): u,v=map(int,input().split()) u-=1 v-=1 g[u].append(v) g[v].append(u) uf=UnionFind(7*n) for v in range(n): for c in range(7): if colors[v][c]=='1' and colors[v][(c+1)%7]=='1': uf.Unite(v+c*n,v+((c+1)%7)*n) for c in range(7): for v in range(n): for u in g[v]: if colors[u][c]=='1' and colors[v][c]=='1': uf.Unite(v+n*c,u+n*c) for _ in range(q): f,x,y=map(int,input().split()) x-=1 y-=1 if f==1: colors[x][y]='1' for c in range(7): if colors[x][c]=='1' and colors[x][(c+1)%7]=='1': uf.Unite(x+c*n,x+((c+1)%7)*n) for c in range(7): for u in g[x]: if colors[x][c]=='1' and colors[u][c]=='1': uf.Unite(x+n*c,u+n*c) elif f==2: print(uf.Count(x))