from sys import setrecursionlimit, stdin def find(parent, i): t = parent[i] if t < 0: return i t = find(parent, t) parent[i] = t return t def unite(parent, i, j): i = find(parent, i) j = find(parent, j) if i == j: return parent[j] += parent[i] parent[i] = j readline = stdin.readline setrecursionlimit(10 ** 6) N, M, Q = map(int, readline().split()) s = [readline() for _ in range(N)] c = [tuple(map(int, x[:-1])) for x in s] parent = [-1] * N for _ in range(M): u, v = map(int, readline().split()) u, v = u - 1, v - 1 up = find(parent, u) vp = find(parent, v) if up != vp: x = tuple(c[up][i] + c[vp][i] for i in range(7)) c[up] = x c[vp] = x unite(parent, u, v) result = [] for _ in range(Q): t, x, y = map(int, readline().split()) if t == 1: x, y = x - 1, y - 1 xp = find(parent, x) z = 1 << (6 - y) a = list(c[xp]) a[y] += 1 c[xp] = tuple(a) elif t == 2: x = x - 1 xp = find(parent, x) a = set() b = c[xp] for i in range(7): if b[i] == 0: break a.add(i) for i in range(6, -1, -1): if b[i] == 0: break a.add(i) d = 0 for i in a: d += b[i] result.append(d) print(*result, sep='\n')