#include using namespace std; using ll = long long; mt19937_64 rng(time(0)); ll MOD[3] = {998244353, 1000000007, 1000000021}; ll BASE[3] = {static_cast(rng() % MOD[0]), static_cast(rng() % MOD[1]), static_cast(rng() % MOD[2]) }; //Rolling Hash on Segment Tree struct Record{ ll hash, pow; }; templatestruct SegTree { private: vector seg; int N = 1; int n; public: SegTree (ll n) : SegTree(vector(n, e())) {} SegTree (const vector &v){ n = v.size(); while (N < n) N *= 2; seg.resize(N*2-1, e()); for (ll i=0; i=0; i--) seg[i] = op(seg[i*2+1], seg[i*2+2]); } void set(int loc, S val){ loc += N-1; seg[loc] = val; while (loc != 0){ loc--; loc >>= 1; seg[loc] = op(seg[(loc<<1)+1], seg[(loc<<1)+2]); } } S prod (int l, int r) const{ l += N-1; r += N-1; S pl = e(), pr = e(); while(l<=r){ if (!(l & 1)){ pl = op(pl, seg[l]); l++; } if (r & 1){ pr = op(seg[r], pr); r--; } l--; r--; l >>= 1; r >>= 1; } return op(pl, pr); } S all_prod() const {return seg[0];} S get (int i) const {return seg[i+N-1];} }; using S = array; S op(S a, S b){ S res; for (int i=0; i<3; i++){ res[i] = {(a[i].hash * b[i].pow % MOD[i] + b[i].hash) % MOD[i], (a[i].pow * b[i].pow)%MOD[i]}; } return res; } S e() { S res; for (int i=0; i<3; i++) res[i] = {0,1}; return res; } S gen(int x){ S res; for (int i=0; i<3; i++) res[i] = {x, BASE[i]}; return res; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* tがSの接頭辞であるか? t[1:|T|]=S[1:|T|] Rolling Hash */ ll N, L, Q, t, k; char c, d; string T; cin >> N >> L >> Q; vector s(N); vector> tree; auto to_hash=[&](string &s){ S x; int N=s.size(); vector v(N); for (int i=0; i(v); }; for (int i=0; i> s[i]; tree.push_back(to_hash(s[i])); }; while(Q--){ cin >> t; if (t == 1){ cin >> k >> c >> d; k--; for (int i=0; i> T; int ans=0; SegTree tree2 = to_hash(T); S x = tree2.all_prod(); for (int i=0; i