#include using namespace std; #include using namespace atcoder; using ll = long long; struct Trie{ vector> node; vector cnt; vector> depth; Trie(){ node.reserve(3000000); cnt.reserve(3000000); depth.reserve(3000000); node.push_back(map()); cnt.push_back(0); depth.push_back(set()); depth[0].insert(0); } void add(string s){ int now = 0; for(int i = 0;i()); cnt.push_back(0); depth.push_back(set()); node[now][s[i]-'a'] = node.size()-1; depth[i+1].insert(node.size()-1); } now = node[now][s[i]-'a']; cnt[now]++; } } int get_cnt(string s){ int now = 0; for(int i = 0;i> Q; Q.push({node[root][c-'a'], node[root][d-'a'],k+1}); depth[k+1].erase(node[root][c-'a']); cnt[node[root][d-'a']] += cnt[node[root][c-'a']]; cnt[node[root][c-'a']] = 0; node[root].erase(c-'a'); while(Q.size()){ auto [a, b,k] = Q.front();Q.pop(); for(int j = 0;j<26;j++){ if(node[a].count(j)==0){ continue; } if(node[b].count(j) == 0){ depth[k+1].erase(node[b][j]); node[b][j] = node[a][j]; node[a].erase(j); }else{ Q.push({node[a][j], node[b][j],k+1}); depth[k+1].erase(node[a][j]); cnt[node[b][j]] += cnt[node[a][j]]; cnt[node[a][j]] = 0; node[a].erase(j); } } } } } } void print(){ for(int i = 0;i S; vector OP; vector T; vector K; vector C,D; void solve(){ Trie trie; for(int i = 0;i> N >> L >> Q; S.resize(N); OP.resize(Q); T.resize(Q); K.resize(Q); C.resize(Q); D.resize(Q); for(int i = 0;i> S[i]; } for(int i = 0;i> OP[i]; if(OP[i] == 2){ cin >> T[i]; }else{ cin >> K[i] >> C[i] >> D[i]; } } solve(); }