import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); UnionFindTree uft = new UnionFindTree(n * 7); boolean[][] colors = new boolean[n][7]; for (int i = 0; i < n; i++) { char[] arr = sc.next().toCharArray(); for (int j = 0; j < 7; j++) { colors[i][j] = (arr[j] == '1'); } for (int j = 0; j < 7; j++) { if (colors[i][j] && colors[i][(j + 1) % 7]) { uft.unite(i * 7 + j, i * 7 + (j + 1) % 7); } } } ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; graph.get(a).add(b); graph.get(b).add(a);; for (int j = 0; j < 7; j++) { if (colors[a][j] && colors[b][j]) { uft.unite(a * 7 + j, b * 7 + j); } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int type = sc.nextInt(); int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (type == 1) { colors[a][b] = true; if (colors[a][(b - 1 + 7) % 7]) { uft.unite(a * 7 + b, a * 7 + (b - 1 + 7) % 7); } if (colors[a][(b + 1) % 7]) { uft.unite(a * 7 + b, a * 7 + (b + 1) % 7); } for (int x : graph.get(a)) { if (colors[x][b]) { uft.unite(a * 7 + b, x * 7 + b); } } } else { sb.append(uft.counts[uft.find(a * 7)]).append("\n"); } } System.out.print(sb); } static class UnionFindTree { int[] parents; int[] counts; public UnionFindTree(int size) { parents = new int[size]; counts = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; counts[i] = 1; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return; } parents[xx] = yy; counts[yy] += counts[xx]; } } }