#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } struct TrieNode { int count; unordered_map children; TrieNode() : count(0) {} }; void insert(TrieNode* root, const string& word) { TrieNode* current = root; for (char c : word) { if (current->children.find(c) == current->children.end()) { current->children[c] = new TrieNode(); } current->children[c]->count += 1; current = current->children[c]; } } vector> char_cur(3000, vector(26)); int calc(const string& t, TrieNode* root, int i) { if (i == t.size()) { return root->count; } char c = t[i]; int res = 0; for (auto [d, child] : root->children) { if (char_cur[i][d - 'a'] == c) { res += calc(t, child, i + 1); } } return res; } int main() { fast_io(); int n, l, q; cin >> n >> l >> q; vector s(n); for (int i = 0; i < n; ++i) { cin >> s[i]; } TrieNode* tree = new TrieNode(); for (const string& t : s) { insert(tree, t); } for (int i = 0; i < l; ++i) { for (int j = 0; j < 26; ++j) { char_cur[i][j] = 'a' + j; } } for (int i = 0; i < q; ++i) { int com; cin >> com; if (com == 1) { int k; char c, d; cin >> k >> c >> d; --k; replace(char_cur[k].begin(), char_cur[k].end(), c, d); } else { string t; cin >> t; cout << calc(t, tree, 0) << "\n"; } } return 0; }