class Node: def __init__(self): self.nex = {} self.ind = [] self.tot = 0 n = int(input()) V0 = Node() Vs = [None] * n ans = [0] * n SS = [] for i in range(n): S = input() SS.append(list(S)) V = V0 for s in S: if s not in V.nex: V.nex[s] = Node() V = V.nex[s] V.tot += 1 Vs[i] = V B = 500 for i, S in enumerate(SS): V = V0 flg = len(S) >= B for s in S: V = V.nex[s] ans[i] += V.tot if flg: V.ind.append(i) Q = int(input()) for _ in range(Q): query = input().split() if query[0] == "1": i = int(query[1]) - 1 s = query[2] SS[i].append(s) V = Vs[i] if s not in V.nex: V.nex[s] = Node() V = V.nex[s] V.tot += 1 for j in V.ind: ans[j] += 1 Vs[i] = V le = len(SS) if le < B: pass elif le == B: ans[i] = 0 V = V0 for s in SS[i]: V = V.nex[s] ans[i] += V.tot V.ind.append(i) else: V.ind.append(i) ans[i] += V.tot else: i = int(query[1]) - 1 le = len(SS) if le < B: ans[i] = 0 V = V0 for s in SS[i]: V = V.nex[s] ans[i] += V.tot print(ans[i])