#include using namespace std; #include using namespace atcoder; #ifdef DEFINED_ONLY_IN_LOCAL #include #define dump(...) cpp_dump(__VA_ARGS__) #else #undef dump #define dump(...) #endif #define rep1(a) for (int i = 0; i < a; i++) #define rep2(i, a) for (int i = 0; i < a; i++) #define rep3(i, a, b) for (int i = a; i < b; i++) #define rep4(i, a, b, c) for (int i = a; i < b; i += c) #define overloadRep(a, b, c, d, e, ...) e #define rep(...) overloadRep(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define endl '\n' #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) using ll = long long; using ull = unsigned long long; const int inf = 1e9; const ll INF = 1e18; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int ddx[8] = {1, 0, -1, 0, 1, -1, 1, -1}; const int ddy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; struct cincout {cincout() {ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15);}} init; template void input(T&... a) {(cin >> ... >> a);} template inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} template inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template istream& operator>>(istream& is, pair& p) {is >> p.first >> p.second; return is;} template ostream& operator<<(ostream& os, const pair& p) {os << p.first << " " << p.second << '\n'; return os;} template istream& operator>>(istream& is, vector& v) {for (T& in : v) {is >> in;} return is;} template ostream& operator<<(ostream& os, const vector& v) {rep(i, (int)v.size()) {os << v[i] << " \n"[i + 1 == (int)v.size()];} return os;} template istream& operator>>(istream& is, vector>& vv) {for (vector& v : vv) {is >> v;} return is;} template ostream& operator<<(ostream& os, vector>& vv) {for (vector& v : vv) {os << v;} return os;} template inline T max(vector x) {return *max_element(x.begin(), x.end());} template inline T min(vector x) {return *min_element(x.begin(), x.end());} template inline T sum(vector x) {return reduce(x.begin(), x.end());} template constexpr auto min(T... a) {return min(initializer_list>{a...});} template constexpr auto max(T... a) {return max(initializer_list>{a...});} inline bool bit(ll x, int p) {return (x >> p) & 1;} inline bool out(int ni, int nj, int h, int w) {return (ni < 0 or ni >= h or nj < 0 or nj >= w);} inline int pc(ll x) {return __builtin_popcountll(x);} void Yes(bool judge = true) {cout << (judge ? "Yes" : "No") << endl;} void No(bool judge = true) {cout << (judge ? "No" : "Yes") << endl;} using namespace std; mt19937_64 rnd(time(0)); static constexpr long long mod = (1LL << 61) - 1; static const long long base = rnd() % (mod - 4) + 2; struct RollingHash { vector hash, power; int n; string s; inline long long add(long long a, long long b) const { if ((a += b) >= mod) a -= mod; return a; } inline long long mul(long long a, long long b) const { __int128_t x = (__int128_t)a * b; return add(x >> 61, x & mod); } explicit RollingHash(const string& S) { n = (int)S.size(); s = S; hash.resize(n + 1, 0); power.resize(n + 1, 1); for (int i = 0; i < n; i++) { hash[i + 1] = add(mul(hash[i], base), S[i]); power[i + 1] = mul(power[i], base); } } inline long long get(int l, int r) const { return add(hash[r], mod - mul(hash[l], power[r - l])); } inline long long get() const { return hash.back(); } inline long long connect(long long hash1, long long hash2, int hash2_len) const { return add(mul(hash1, power[hash2_len]), hash2); } inline int lcp(int a, int b) const { int len = min((int)hash.size() - a, (int)hash.size() - b); int left = 0, right = len; while (right - left > 1) { int mid = (left + right) / 2; if (get(a, a + mid) != get(b, b + mid)) { right = mid; } else { left = mid; } } return left; } inline int lcp(const RollingHash& T, int a, int b) const { int len = min((int)hash.size() - a, (int)T.hash.size() - b); int left = 0, right = len; while (right - left > 1) { int mid = (left + right) / 2; if (get(a, a + mid) != T.get(b, b + mid)) { right = mid; } else { left = mid; } } return left; } }; #include // mt19937_64 rnd(time(0)); // static constexpr long long mod = (1LL << 61) - 1; // static const long long base = rnd() % (mod - 4) + 2; using D = pair; D op(D l, D r) { auto [a, b] = l; auto [c, d] = r; __int128_t x = (__int128_t)a * d + c; return D(x % mod, ((__int128_t)b * d) % mod); } D e() { return D(0, 1); } D op_(D l, D r) { auto [a, b] = l; auto [c, d] = r; __int128_t x = (__int128_t)c * b + a; return D(x % mod, ((__int128_t)b * d) % mod); } struct RollingHashTree { segtree seg; segtree rseg; bool reverse; explicit RollingHashTree(const string &s = "", bool reverse_ = false) : reverse(reverse_) { int n = s.size(); seg = segtree(n); if (reverse) rseg = segtree(n); rep(i, n) { seg.set(i, D(s[i], base)); if (reverse) rseg.set(i, D(s[i], base)); } } inline void set(int i, char c) { seg.set(i, D(c, base)); if (reverse) rseg.set(i, D(c, base)); } inline long long get(int l, int r) { auto [a, b] = seg.prod(l, r); return a; } inline long long rget(int l, int r) { auto [a, b] = rseg.prod(l, r); return a; } }; int main() { int n, l, q; cin >> n >> l >> q; vector s(n); cin >> s; vector rolling_hash(n); rep(i, n) { rolling_hash[i] = RollingHashTree(s[i]); } while (q--) { int type; cin >> type; if (type == 1) { int k; char c, d; cin >> k >> c >> d; k--; rep(i, n) { if (s[i][k] == c) { s[i][k] = d; rolling_hash[i].set(k, d); } } } else { string t; cin >> t; int m = t.size(); RollingHash rol(t); int ans = 0; rep(i, n) { if (rolling_hash[i].get(0, m) == rol.get()) ans++; } cout << ans << endl; } } return 0; }