#region Header #!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools from queue import PriorityQueue import bisect import heapq def input(): return sys.stdin.readline()[:-1] sys.setrecursionlimit(1000000) #endregion # _INPUT = """3 2 3 # 1010000 # 1000000 # 0010000 # 1 2 # 1 3 # 2 1 0 # 1 1 2 # 2 1 0 # """ # sys.stdin = io.StringIO(_INPUT) def dfs(G, colors, seen, city, color): next_colors = set([color]) i = (color + 1) % 7 while colors[city][i]: next_colors.add(i) i = (i + 1) % 7 if i == color: break i = (color - 1) % 7 while colors[city][i]: next_colors.add(i) i = (i - 1) % 7 if i == color: break n = 0 for next_color in next_colors: if not seen[city][next_color]: n += 1 seen[city][next_color] = True for next_city in G[city]: if colors[next_city][next_color] and (not seen[next_city][next_color]): n += dfs(G, colors, seen, next_city, next_color) return n def main(): N, M, Q = map(int, input().split()) colors = [[False for _ in range(7)] for _ in range(N)] for i in range(N): s = input() for j in range(7): if s[j] == '1': colors[i][j] = True G = [list() for _ in range(N)] for _ in range(M): _u, _v = map(int, input().split()) G[_u-1].append(_v-1) G[_v-1].append(_u-1) color = 0 for _ in range(Q): t, x, y = map(int, input().split()) if t == 1: colors[x-1][y-1] = True else: seen = [[False for _ in range(7)] for _ in range(N)] n = dfs(G, colors, seen, x-1, 0) print(n) if __name__ == '__main__': main()