#include using namespace std; int main(){ int N;cin >> N; vector S(N); for(string &s:S) cin >> s; vector node({0}); vector> nex(1,vector(26,-1)),cnt(1); for(int i=0;i(26,-1)); cnt.emplace_back(vector()); } now = nex[now][z];cnt[now].emplace_back(i); } } vector ans(N),pos(N); for(int i=0;i> Q; for(int i=0;i> t >> x;x--; if(t == 1){ char c;cin >> c; int z = c-'a'; if(nex[pos[x]][z] == -1){ nex[pos[x]][z] = node.size(); node.emplace_back(c); nex.emplace_back(vector(26,-1)); cnt.emplace_back(vector()); } pos[x] = nex[pos[x]][z]; ans[x] += cnt[pos[x]].size(); cnt[pos[x]].emplace_back(x); for(int itr:cnt[pos[x]]) ans[itr]++; } else{ cout << ans[x] << "\n"; } } }