from string import ascii_lowercase n, l, q = map(int, input().split()) s = [input() for _ in range(n)] tree = {} for t in s: current = tree for c in t: if c in current: current[c][0] += 1 else: current[c] = [1, {}] current = current[c][1] char_cur = [{c: c for c in ascii_lowercase} for _ in range(l)] for _ in range(q): query = input().split() com = int(query[0]) if com == 1: k, c, d = query[1:] k = int(k) - 1 for ch in ascii_lowercase: if char_cur[k][ch] == c: char_cur[k][ch] = d else: t = query[1] cur = [tree] ans = 0 # count the number of words that start with t for i in range(len(t)): cur_next = [] ans = 0 for tr in cur: for key, value in tr.items(): if char_cur[i][key] == t[i]: cur_next.append(value[1]) ans += value[0] cur = cur_next print(ans)