#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") template void bAdd(vector &bit, int pos, const T &val) { const int bitN = bit.size(); for (int x = pos; x < bitN; x |= x + 1) bit[x] += val; } template T bSum(const vector &bit, int pos) { T ret = 0; for (int x = pos; x > 0; x &= x - 1) ret += bit[x - 1]; return ret; } template T bSum(const vector &bit, int pos0, int pos1) { return bSum(bit, pos1) - bSum(bit, pos0); } //////////////////////////////////////////////////////////////////////////////// // 2^61 - 1 = 2'305'843'009'213'693'951 struct ModLong61 { static constexpr unsigned long long M = (1ULL << 61) - 1; unsigned long long x; constexpr ModLong61() : x(0ULL) {} constexpr ModLong61(unsigned x_) : x(x_) {} constexpr ModLong61(unsigned long long x_) : x(x_ % M) {} constexpr ModLong61(int x_) : x((x_ < 0) ? (x_ + static_cast(M)) : x_) {} constexpr ModLong61(long long x_) : x(((x_ %= static_cast(M)) < 0) ? (x_ + static_cast(M)) : x_) {} ModLong61 &operator+=(const ModLong61 &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; } ModLong61 &operator-=(const ModLong61 &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; } ModLong61 &operator*=(const ModLong61 &a) { const unsigned __int128 y = static_cast(x) * a.x; x = (y >> 61) + (y & M); x = (x >= M) ? (x - M) : x; return *this; } ModLong61 &operator/=(const ModLong61 &a) { return (*this *= a.inv()); } ModLong61 pow(long long e) const { if (e < 0) return inv().pow(-e); ModLong61 a = *this, b = 1ULL; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b; } ModLong61 inv() const { unsigned long long a = M, b = x; long long y = 0, z = 1; for (; b; ) { const unsigned long long q = a / b; const unsigned long long c = a - q * b; a = b; b = c; const long long w = y - static_cast(q) * z; y = z; z = w; } assert(a == 1ULL); return ModLong61(y); } ModLong61 operator+() const { return *this; } ModLong61 operator-() const { ModLong61 a; a.x = x ? (M - x) : 0ULL; return a; } ModLong61 operator+(const ModLong61 &a) const { return (ModLong61(*this) += a); } ModLong61 operator-(const ModLong61 &a) const { return (ModLong61(*this) -= a); } ModLong61 operator*(const ModLong61 &a) const { return (ModLong61(*this) *= a); } ModLong61 operator/(const ModLong61 &a) const { return (ModLong61(*this) /= a); } template friend ModLong61 operator+(T a, const ModLong61 &b) { return (ModLong61(a) += b); } template friend ModLong61 operator-(T a, const ModLong61 &b) { return (ModLong61(a) -= b); } template friend ModLong61 operator*(T a, const ModLong61 &b) { return (ModLong61(a) *= b); } template friend ModLong61 operator/(T a, const ModLong61 &b) { return (ModLong61(a) /= b); } explicit operator bool() const { return x; } bool operator==(const ModLong61 &a) const { return (x == a.x); } bool operator!=(const ModLong61 &a) const { return (x != a.x); } friend std::ostream &operator<<(std::ostream &os, const ModLong61 &a) { return os << a.x; } }; //////////////////////////////////////////////////////////////////////////////// #include #ifdef LOCAL mt19937_64 rng(58); #else mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #endif const ModLong61 BASE = static_cast(rng()); //////////////////////////////////////////////////////////////////////////////// char buf[10010]; int N, L, Q; vector S; int main() { for (; ~scanf("%d%d%d", &N, &L, &Q); ) { S.resize(N); for (int i = 0; i < N; ++i) { scanf("%s", buf); S[i] = buf; } vector pw(L + 1); pw[0] = 1; for (int j = 1; j <= L; ++j) pw[j] = pw[j - 1] * BASE; vector> bits(N, vector(L, 0)); for (int i = 0; i < N; ++i) { for (int j = 0; j < L; ++j) { bAdd(bits[i], j, pw[j] * S[i][j]); } } for (; Q--; ) { int O; scanf("%d", &O); if (O == 1) { int K; char C, D; scanf("%d %c %c", &K, &C, &D); --K; for (int i = 0; i < N; ++i) if (S[i][K] == C) { S[i][K] = D; bAdd(bits[i], K, pw[K] * (D - C)); } } else if (O == 2) { scanf("%s", buf); const string T = buf; const int TLen = T.size(); ModLong61 tar = 0; for (int j = 0; j < TLen; ++j) { tar += pw[j] * T[j]; } int ans = 0; for (int i = 0; i < N; ++i) { if (bSum(bits[i], TLen) == tar) { ++ans; } } printf("%d\n", ans); } else { assert(false); } } } return 0; }