#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=998244353 import sys input=sys.stdin.readline class Bit:#0-indexed を 1-indexedに変換するので、0-indexedを入れる def __init__(self, n): self.size = n + 1 self.tree = [0] * (n + 2) self.depth = (n + 1).bit_length() def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def lower_bound(self, x): """ 累積和がx以上になる最小のindexと、その直前までの累積和 """ sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos, sum_ n = int(input()) sl = [[] for _ in range(n)] for i in range(n): st = input().rstrip() for ss in st: sl[i].append(ord(ss) - ord('a')) sl2 = [sl[i][:] for i in range(n)] q = int(input()) qry = [] for _ in range(q): qe = list(map(str,input().rstrip().split())) if qe[0] == '1': sl2[int(qe[1]) - 1].append(ord(qe[2]) - ord('a')) qry.append(qe) nex = [[-1] * 26 for _ in range(400000)] lenn = 1 g = [[] for _ in range(400000)] for i in range(n): now = 0 for z in sl2[i]: if nex[now][z] == -1: nex[now][z] = lenn g[now].append(lenn) g[lenn].append(now) lenn += 1 now = nex[now][z] def EulerTour(n, X, i0): done = [0] * n par = [-1] * n Q = deque([~i0, i0]) # 根をスタックに追加 ET = [] while Q: i = Q.pop() if i >= 0: # 行きがけの処理 done[i] = 1 ET.append(i) for a in X[i]: if done[a]: continue par[a] = i Q.append(~a) # 帰りがけの処理をスタックに追加 Q.append(a) # 行きがけの処理をスタックに追加 else: # 帰りがけの処理 i = ~i ET.append(i) return ET ET = EulerTour(lenn,g,0) beg = [-1] * lenn end = [-1] * lenn for i in range(len(ET)): if beg[ET[i]] == -1: beg[ET[i]] = i else: end[ET[i]] = i bit = Bit(lenn * 2) pos = [0] * n for i in range(n): now = 0 for z in sl[i]: now = nex[now][z] bit.add(beg[now],1) bit.add(end[now],-1) pos[i] = now for i in range(q): if qry[i][0] == '1': x = int(qry[i][1]) - 1 z = ord(qry[i][2]) - ord('a') now = nex[pos[x]][z] bit.add(beg[now],1) bit.add(end[now],-1) pos[x] = now else: x = int(qry[i][1]) - 1 print(bit.sum(beg[pos[x]]))