#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, l, q; cin >> n >> l >> q; vector s(n); for(auto &&ss : s) cin >> ss; sort(s.begin(), s.end()); vector ord(n); vector used(n); iota(ord.begin(), ord.end(), 0); auto fr = [&](string &t){ int m = t.size(); int ok = -1, ng = n, mid; while(ok + 1 < ng){ mid = (ok + ng) / 2; (t >= s[ord[mid]].substr(0, m) ? ok : ng) = mid; } return ok; }; auto fl = [&](string &t){ int m = t.size(); int ok = -1, ng = n, mid; while(ok + 1 < ng){ mid = (ok + ng) / 2; (t > s[ord[mid]].substr(0, m) ? ok : ng) = mid; } return ok; }; while(q--){ int cmd; cin >> cmd; if(cmd == 1){ int k; char c1, c2; cin >> k >> c1 >> c2; k--; for(int i = 0; i < n; i++){ if(s[i][k] == c1){ s[i][k] = c2; used[i] = true; }else used[i] = false; } stable_sort(ord.begin(), ord.end(), [&](int lhs, int rhs){ if(used[lhs] ^ used[rhs]) return s[lhs] < s[rhs]; return false; }); }else{ string t; cin >> t; cout << fr(t) - fl(t) << '\n'; } } }