#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; template struct fenwick_tree { fenwick_tree() = default; fenwick_tree(int n) { this->n = n; dat = vector(n); } void add(int i, T x) { i++; while (i <= n) { dat[i - 1] += x; i += i & -i; } } T operator[](int i) { return sum(i, i + 1); } T sum(int l, int r) { return sum(r) - sum(l); } int n; private: vector dat; T sum(int r) { T ret = 0; while (r > 0) { ret += dat[r - 1]; r -= r & -r; } return ret; } }; template struct modint { ll value; modint(ll x = 0) { if (x >= 0) { value = x % MOD; } else { value = MOD - (-x) % MOD; } } modint operator-() const { return modint(-value); } modint operator+() const { return modint(*this); } modint &operator+=(const modint &other) { value += other.value; if (value >= MOD) { value -= MOD; } return *this; } modint &operator-=(const modint &other) { value += MOD - other.value; if (value >= MOD) { value -= MOD; } return *this; } modint &operator*=(const modint other) { value = value * other.value % MOD; return *this; } modint &operator/=(modint other) { (*this) *= other.inv(); return *this; } modint operator+(const modint &other) const { return modint(*this) += other; } modint operator-(const modint &other) const { return modint(*this) -= other; } modint operator*(const modint &other) const { return modint(*this) *= other; } modint operator/(const modint &other) const { return modint(*this) /= other; } modint pow(ll x) const { modint ret(1), mul(value); while (x) { if (x & 1) { ret *= mul; } mul *= mul; x >>= 1; } return ret; } modint inv() const { return pow(MOD - 2); } bool operator==(const modint &other) const { return value == other.value; } bool operator!=(const modint &other) const { return value != other.value; } friend ostream &operator<<(ostream &os, const modint &x) { return os << x.value; } friend istream &operator>>(istream &is, modint &x) { ll v; is >> v; x = modint(v); return is; } }; using mod998 = modint<998244353>; using mod107 = modint<1000000007>; namespace random_generator { mt19937_64 generate; void init() { random_device seed_gen; generate = mt19937_64(seed_gen()); } template T random_int(T x) { assert(x > 0); return generate() % x; } template T random_int(T x, T y) { assert(x < y); return x + generate() % (y - x); } template T get_elememt(vector &a) { const int n = a.size(); int idx = random_int(0, n); swap(a[n - 1], a[idx]); int ret = a.back(); a.pop_back(); return ret; } template vector random_array_int(int n, T lo, T hi, bool no_dup = false) { vector ret(n); if (!no_dup) { for (int i = 0; i < n; i++) { ret[i] = random_int(lo, hi); } } else { set st; for (int i = 0; i < n; i++) { int r = random_int(lo, hi); while (st.count(r)) { r = random_int(lo, hi); } ret[i] = r; st.insert(r); } } return ret; } string random_alphabet(int n, bool lower = true) { string ret; for (int i = 0; i < n; i++) { int idx = random_int(26); ret.push_back(char((lower ? 'a' : 'A') + idx)); } return ret; } string random_string(int n, string s) { string ret; int m = s.size(); for (int i = 0; i < n; i++) { int idx = random_int(m); ret.push_back(s[idx]); } return ret; } template vector> random_array_2D(int h, int w, T lo, T hi) { vector> ret(h, vector(w)); for (int i = 0; i < h; i++) { ret[i] = random_array_int(w, lo, hi); } return ret; } vector random_alphabet_2D(int h, int w, bool lower = true) { vector ret(h); for (int i = 0; i < h; i++) { ret[i] = random_alphabet(w, lower); } return ret; } vector> random_tree(int n) { vector a = random_array_int(n - 2, 1, n + 1); vector d(n + 1); for (int i = 0; i < n - 2; i++) { d[a[i]]++; } for (int i = 1; i <= n; i++) { d[i]++; } vector> ret; set pq; for (int i = 1; i <= n; i++) { if (d[i] == 1) { pq.insert(i); } } for (int i = 0; i < n - 2; i++) { int v = (*pq.begin()); pq.erase(v); ret.push_back(make_pair(v, a[i])); d[v]--; d[a[i]]--; if (d[a[i]] == 1) { pq.insert(a[i]); } else if (d[a[i]] == 0) { pq.erase(a[i]); } } for (int i = 1; i <= n; i++) { if (d[i] == 1) { for (int j = i + 1; j <= n; j++) { if (d[j] == 1) { ret.push_back(make_pair(i, j)); break; } } break; } } return ret; } vector> random_bintree(int n) { vector> ret; vector roots = {random_int(1, n + 1)}; vector leaves; for (int i = 1; i <= n; i++) { if (i != roots.back()) { leaves.push_back(i); } } while (!leaves.empty()) { int root = get_elememt(roots); int leaf = get_elememt(leaves); ret.push_back(make_pair(root, leaf)); roots.push_back(leaf); if (!leaves.empty()) { int leaf = get_elememt(leaves); ret.push_back(make_pair(root, leaf)); roots.push_back(leaf); } } return ret; } vector> random_undigraph(int n, int m, bool connected = true) { vector> edges; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { edges.push_back(make_pair(i + 1, j + 1)); } } int ed = edges.size(); if (!connected) { vector> ret; vector idxs = random_array_int(m, 0, ed, true); for (int idx : idxs) { ret.push_back(edges[idx]); } return ret; } else { vector> ret; while (true) { ret.clear(); vector idxs = random_array_int(m, 0, ed, true); vector parent(n); vector> sets(n); for (int i = 0; i < n; i++) { parent[i] = i; sets[i].push_back(i); } for (int idx : idxs) { ret.push_back(edges[idx]); auto [a, b] = edges[idx]; a--; b--; if (parent[a] != parent[b]) { if (sets[parent[a]].size() < sets[parent[b]].size()) { swap(a, b); } for (int x : sets[parent[b]]) { parent[x] = parent[a]; sets[parent[a]].push_back(x); } sets[parent[b]].clear(); } } bool ok = true; for (int i = 0; i < n; i++) { if (parent[i] != parent[0]) { ok = false; break; } } if (ok) { return ret; } } } } }; // namespace random_generator struct setup_random { setup_random() { random_generator::init(); } } setup_random_instance; struct rolling_hash { int base; fenwick_tree hash1; fenwick_tree hash2; rolling_hash() = default; rolling_hash(const string &s, int base) { this->base = base; int n = s.size(); hash1 = fenwick_tree(n + 1); hash2 = fenwick_tree(n + 1); for (int i = 0; i < n; i++) { hash1.add(i, mod107(s[i] - 'a' + 1) * mod107(base).pow(i)); hash2.add(i, mod998(s[i] - 'a' + 1) * mod998(base).pow(i)); } } void change(int i, char c1, char c2) { hash1.add(i, mod107(c2 - c1) * mod107(base).pow(i)); hash2.add(i, mod998(c2 - c1) * mod998(base).pow(i)); } pair get(int len) { return {hash1.sum(0, len), hash2.sum(0, len)}; } }; int main() { int base = random_generator::random_int(1000, 10000); int N, L, Q; cin >> N >> L >> Q; vector rh(N); vector S(N); for (int i = 0; i < N; i++) { cin >> S[i]; rh[i] = rolling_hash(S[i], base); } while (Q--) { int t; cin >> t; if (t == 1) { int k; char c, d; cin >> k >> c >> d; k--; for (int i = 0; i < N; i++) { if (S[i][k] == c) { rh[i].change(k, c, d); S[i][k] = d; } } } else { string T; cin >> T; rolling_hash rt(T, base); int ans = 0; for (int i = 0; i < N; i++) { int n = S[i].size(); int m = T.size(); if (n < m) continue; auto [h1, h2] = rt.get(m); auto [h3, h4] = rh[i].get(m); if (h1 == h3 && h2 == h4) ans++; } cout << ans << '\n'; } } }