#include<bits/stdc++.h>
using namespace std;

template<typename X, typename Y>
bool chmax(X& a, Y b) { return (a < b) ? a = b, 1 : 0; }

template<typename X, typename Y>
bool chmin(X& a, Y b) { return (a > b) ? a = b, 1 : 0; }

using ll = long long;

const int N = 5e5+5;

int k;
string s;

int go[N][26], fail[N], cnt[N], nodes = 0;
vector<int> order;

int insert(string s) {
    int u = 0;
    for (char ch : s) {
        int c = ch - 'a';
        if (!go[u][c]) go[u][c] = ++nodes;
        u = go[u][c];
    }
    return u;
}

void build() {
    queue<int> q;
    for (int c = 0; c < 26; c++)
        if (go[0][c]) q.push(go[0][c]);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        order.push_back(u);
        for (int c = 0; c < 26; c++) {
            if (go[u][c]) {
                fail[go[u][c]] = go[fail[u]][c];
                q.push(go[u][c]);
            } else go[u][c] = go[fail[u]][c];
        }
    } 
}

void calc(string s) {
    int u = 0;
    for (char ch : s) {
        int c = ch - 'a';
        u = go[u][c];
        cnt[u]++;
    }
    for (int i = (int)order.size() - 1; i >= 0; i--) {
        int u = order[i];
        cnt[fail[u]] += cnt[u];
    }
}

void solve() {
    cin >> s >> k;
    vector<int> p(k);
    for (int i = 0; i < k; i++) {
        string w; cin >> w;
        p[i] = insert(w);
    }
    build();
    calc(s);
    for (int i = 0; i < k; i++) cout << cnt[p[i]] << '\n';
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int tests = 1; // cin >> tests;
    while (tests--) solve();

    #ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}
