#include #include #include using namespace std; struct TrieNode { TrieNode* children[26]; int count; TrieNode() { for (int i = 0; i < 26; i++) { children[i] = nullptr; } count = 0; } }; class Trie { public: Trie() { root = new TrieNode(); } void insert(const string& word) { TrieNode* current = root; for (char c : word) { int index = c - 'a'; if (current->children[index] == nullptr) { current->children[index] = new TrieNode(); } current = current->children[index]; current->count++; } } int query(const string& word) { TrieNode* current = root; int result = 0; for (char c : word) { int index = c - 'a'; if (current->children[index] == nullptr) { break; } current = current->children[index]; result = current->count; } return result; } private: TrieNode* root; }; int main() { int n; cin >> n; Trie trie; for (int i = 0; i < n; i++) { string godName; cin >> godName; trie.insert(godName); } int q; cin >> q; for (int i = 0; i < q; i++) { string humanName; cin >> humanName; cout << trie.query(humanName) << endl; } return 0; }