#include <bits/stdc++.h>
using namespace std;
const int ALPHABET_SIZE = 26;
struct lowercase_string: string
{
lowercase_string()
{
cin >> *this;
}
int index(int i) const
{
return at(i)-'a';
}
};
template<class T>
struct strings: vector<T>
{
strings()
{
size_t count; cin >> count, this->resize(count);
}
};
struct index_vector: vector<int>
{
int next(int i) const
{
size_t j = upper_bound(begin(),end(),i)-begin();
return j == size() ? -1 : at(j);
}
};
struct string_index: array<index_vector,ALPHABET_SIZE>
{
string_index(const lowercase_string& s)
{
for (int n = s.size(), i = 0; i < n; ++i)
at(s.index(i)).push_back(i);
}
};
template<class T,class U>
struct trie: array<T*,ALPHABET_SIZE>
{
trie()
{
this->fill(nullptr);
}
void add_string(const U& s)
{
auto p = this;
for (int n = s.size(), j, i = 0; i < n; ++i, p = p->at(j))
if (p->at(j=s.index(i)) == nullptr)
p->at(j) = new T;
}
};
template<class T>
struct queries_trie: trie<queries_trie<T>,T>
{
int count;
queries_trie() : count(0) {}
void add_subsequences(const string_index& i, int j = -1)
{
for (int k, l = 0; l < ALPHABET_SIZE; l++)
if (this->at(l) != nullptr and (k = i[l].next(j)) >= 0)
this->at(l)->count++,
this->at(l)->add_subsequences(i,k);
}
void add_subsequences(const T& s)
{
add_subsequences(string_index(s));
}
int matched_subsequences(const T& s) const
{
auto p = this;
for (int n = s.size(), i = 0; i < n; ++i)
p = p->at(s.index(i));
return p->count;
}
};
int main()
{
ios_base::sync_with_stdio(false),
cin.tie(nullptr), cout.tie(nullptr);
strings<lowercase_string> input, query;
queries_trie<lowercase_string> t;
for(auto s: query)
t.add_string(s);
for(auto s: input)
t.add_subsequences(s);
for(auto s: query)
cout << t.matched_subsequences(s) << '\n';
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IEFMUEhBQkVUX1NJWkUgPSAyNjsKCnN0cnVjdCBsb3dlcmNhc2Vfc3RyaW5nOiBzdHJpbmcKewogICAgbG93ZXJj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LCBqLCBpID0gMDsgaSA8IG47ICsraSwgcCA9IHAtPmF0KGopKQogICAgICAgICAgICBpZiAocC0+YXQoaj1zLmluZGV4KGkpKSA9PSBudWxscHRyKQogICAgICAgICAgICAgICAgcC0+YXQoaikgPSBuZXcgVDsKICAgIH0KfTsKCnRlbXBsYXRlPGNsYXNzIFQ+CnN0cnVjdCBxdWVyaWVzX3RyaWU6IHRyaWU8cXVlcmllc190cmllPFQ+LFQ+CnsKICAgIGludCBjb3VudDsKCiAgICBxdWVyaWVzX3RyaWUoKSA6IGNvdW50KDApIHt9CgogICAgdm9pZCBhZGRfc3Vic2VxdWVuY2VzKGNvbnN0IHN0cmluZ19pbmRleCYgaSwgaW50IGogPSAtMSkKICAgIHsKICAgICAgICBmb3IgKGludCBrLCBsID0gMDsgbCA8IEFMUEhBQkVUX1NJWkU7IGwrKykKICAgICAgICAgICAgaWYgKHRoaXMtPmF0KGwpICE9IG51bGxwdHIgYW5kIChrID0gaVtsXS5uZXh0KGopKSA+PSAwKQogICAgICAgICAgICAgICAgdGhpcy0+YXQobCktPmNvdW50KyssCiAgICAgICAgICAgICAgICB0aGlzLT5hdChsKS0+YWRkX3N1YnNlcXVlbmNlcyhpLGspOwogICAgfQoKICAgIHZvaWQgYWRkX3N1YnNlcXVlbmNlcyhjb25zdCBUJiBzKQogICAgewogICAgICAgIGFkZF9zdWJzZXF1ZW5jZXMoc3RyaW5nX2luZGV4KHMpKTsKICAgIH0KCiAgICBpbnQgbWF0Y2hlZF9zdWJzZXF1ZW5jZXMoY29uc3QgVCYgcykgY29uc3QKICAgIHsKICAgICAgICBhdXRvIHAgPSB0aGlzOwoKICAgICAgICBmb3IgKGludCBuID0gcy5zaXplKCksIGkgPSAwOyBpIDwgbjsgKytpKQogICAgICAgICAgICBwID0gcC0+YXQocy5pbmRleChpKSk7CgogICAgICAgIHJldHVybiBwLT5jb3VudDsKICAgIH0KfTsKCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0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