#include using namespace std; constexpr int mod[] = {998244353,1000000007}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; map,vector>mp; vectorans(N); vectortmp(N); vector>hs(N,vector(2,0)); vectorS(N); for(int i = 0; i < N; i++) { cin >> S[i]; for(int j = 0; j < S[i].size(); j++) { for(int k = 0; k < 2; k++) { hs[i][k] = (27ll*hs[i][k]+S[i][j]-'a')%mod[k]; } mp[{hs[i][0],hs[i][1]}].push_back(i); } } for(int i = 0; i < N; i++) { hs[i][0] = hs[i][1] = 0; for(int j = 0; j < S[i].size(); j++) { for(int k = 0; k < 2; k++) { hs[i][k] = (27ll*hs[i][k]+S[i][j]-'a')%mod[k]; } ans[i] += mp[{hs[i][0],hs[i][1]}].size(); } } int Q; cin >> Q; while(Q--) { int f; cin >> f; if(f == 1) { int x; char c; cin >> x >> c; x--; for(int j = 0; j < 2; j++) { hs[x][j] = (27ll*hs[x][j]+c-'a')%mod[j]; } mp[{hs[x][0],hs[x][1]}].push_back(x); for(int i:mp[{hs[x][0],hs[x][1]}]) { ans[i]++; } } else { int x; cin >> x; x--; cout << ans[x] << '\n'; } } }