def convert(str): return [ord(str[i]) - 0x61 for i in range(len(str))] N, L, Q = map(int, input().split()) S = [convert(input().strip()) for _ in range(N)] class Node: __slots__ = ("sum", "children", "parent") def __init__(self): self.sum = 0 self.children = [None] * 26 self.parent = None # (sum, children, parent) trie = Node() by_index_char = [[{} for _ in range(26)] for _ in range(L)] def add(str, amount = 1): cur = trie cur.sum += amount for i in range(L): c = str[i] if not cur.children[c]: node = Node() node.parent = cur cur.children[c] = node by_index_char[i][c][id(node)] = node cur = cur.children[c] cur.sum += amount def substitute(k, c, d): stack = [] for node in by_index_char[k][c].values(): parent = node.parent if not parent: continue parent.children[c] = None if merged := parent.children[d]: stack.append((node, merged, k)) else: parent.children[d] = node by_index_char[k][d][id(node)] = node by_index_char[k][c].clear() while stack: src, dst, k = stack.pop() dst.sum += src.sum for c in range(26): if src_child := src.children[c]: if dst_child := dst.children[c]: by_index_char[k + 1][c].pop(id(src_child)) stack.append((src_child, dst_child, k + 1)) else: src_child.parent = dst dst.children[c] = src_child def count_prefix(t): cur = trie for c in t: cur = cur.children[c] if not cur: return 0 return cur.sum for s in S: add(s) for _ in range(Q): values = input().split() if values[0] == "1": k = int(values[1]) - 1 c = ord(values[2]) - 0x61 d = ord(values[3]) - 0x61 substitute(k, c, d) else: t = convert(values[1]) print(count_prefix(t))