#include #include using namespace std; using namespace atcoder; #define emb emplace_back using ll = long long; int main(){ cin.tie(0);ios::sync_with_stdio(false); //入力 int N;cin >> N; vector S(N); for(string &s:S) cin >> s; int node_size = 1; vector> nex(1,vector(26,-1)); vector cnt({0}); vector node_itr(N); for(int i=0;i(26,-1)); cnt.emplace_back(0); } now_node = nex[now_node][z]; cnt[now_node]++; } node_itr[i] = now_node; } int Q;cin >> Q; for(int i=0;i> t; if(t==1){ int x;char c;cin >> x >> c;x--; int z = c-'a'; S[x] += c; if(nex[node_itr[x]][z] == -1){ nex[node_itr[x]][z] = node_size++; nex.emplace_back(vector(26,-1)); cnt.emplace_back(0); } node_itr[x] = nex[node_itr[x]][z]; cnt[node_itr[x]]++; } else{ int x;cin >> x;x--; int ans = 0,now_node = 0; for(char c:S[x]){ now_node = nex[now_node][c-'a']; ans += cnt[now_node]; } cout << ans << "\n"; } } }