#include #include using namespace std; using namespace atcoder; using m1 = modint998244353; using m2 = modint1000000007; using P = pair; unsigned int xorshift() { static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned int t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } P op(P a, P b) { return {a.first + b.first, a.second + b.second}; } P e() { return {0, 0}; } int main() { int n, l, q; cin >> n >> l >> q; vector s(n); for (int i = 0; i < n; i++) { cin >> s[i]; } m1 b1 = xorshift(); m2 b2 = xorshift(); vector p1(l, 1); vector p2(l, 1); for (int i = 1; i < l; i++) { p1[i] = p1[i - 1] * b1; p2[i] = p2[i - 1] * b2; } vector> seg(n, segtree(l)); for (int i = 0; i < n; i++) { for (int j = 0; j < l; j++) { int x = s[i][j] - 'a' + 1; m1 h1 = p1[j] * x; m2 h2 = p2[j] * x; seg[i].set(j, {h1, h2}); } } while (q--) { int t; cin >> t; if (t == 1) { int k; char c, d; cin >> k >> c >> d; k--; int x = d - 'a' + 1; for (int i = 0; i < n; i++) { if (s[i][k] == c) { m1 h1 = p1[k] * x; m2 h2 = p2[k] * x; seg[i].set(k, {h1, h2}); s[i][k] = d; } } } else { string pre; cin >> pre; int len = pre.size(); m1 h1 = 0; m2 h2 = 0; for (int i = 0; i < len; i++) { int x = pre[i] - 'a' + 1; h1 += p1[i] * x; h2 += p2[i] * x; } int ans = 0; for (int i = 0; i < n; i++) { P cur = seg[i].prod(0, len); if (cur.first == h1 && cur.second == h2) { ans++; } } cout << ans << endl; } } }