#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';
}