#include <bits/stdc++.h>   using namespace std;   int m, n, L, cnt, sum[1000005];   char s[1000005], x[1000005];   struct Node {     Node *par, *go[26];     int val, sum, flag, num;     void Clear(int _val) {       par = NULL;       for (int i = 0; i < 26; i++) go[i] = NULL;       sum = flag = 0;       val = _val;     }   } * root, *last, *a[1000005 * 2], *b[1000005 * 2];   void Extend(int w) {     Node *p = last, *np = new Node;     a[++cnt] = np;     np->num = cnt;     np->Clear(p->val + 1);     for (; p && (!(p->go[w])); p = p->par) p->go[w] = np;     if (!p)       np->par = root;     else {       Node *q = p->go[w];       if (q->val == p->val + 1)         np->par = q;       else {         Node *nq = new Node;         a[++cnt] = nq;         nq->num = cnt;         nq->Clear(p->val + 1);         for (int i = 0; i < 26; i++) nq->go[i] = q->go[i];         nq->par = q->par;         q->par = np->par = nq;         for (; p && (p->go[w] == q); p = p->par) p->go[w] = nq;       }     }     last = np;   }   void BuildSAM() {     scanf( %s , &s);     m = strlen(s);     cnt = 0;     root = new Node;     root->Clear(0);     root->num = 0;     last = root;     for (int i = 0; i < m; i++) Extend(s[i] -  a );   }   void DP() {     for (Node *p = last; p; p = p->par) p->sum = 1;     for (int i = 0; i <= m; i++) sum[i] = 0;     for (int i = 1; i <= cnt; i++) sum[a[i]->val]++;     for (int i = 1; i <= m; i++) sum[i] += sum[i - 1];     for (int i = 1; i <= cnt; i++) b[sum[a[i]->val]--] = a[i];     for (int i = cnt; i >= 1; i--) {       Node *p = b[i];       for (int j = 0; j < 26; j++)         if (p->go[j]) {           p->sum += p->go[j]->sum;         }     }   }   int main() {     BuildSAM();     DP();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , &x);       L = strlen(x);       Node *p = root;       int len = 0;       for (int j = 0; j < L; j++) {         int w = x[j] -  a ;         while (p && (!p->go[w])) p = p->par;         if (!p) p = root;         len = min(len, p->val);         if (p->go[w]) {           p = p->go[w];           len++;         }       }       int ans = 0;       for (int j = 0; j < L; j++) {         int w = x[j] -  a ;         while (p && (!p->go[w])) p = p->par;         if (!p) {           p = root;           continue;         }         len = min(len + 1, p->val + 1);         p = p->go[w];         while (p->par && (p->par->val >= L)) p = p->par;         if (p->flag == i) continue;         if (len >= L) {           ans += p->sum;           p->flag = i;         }       }       printf( %d n , ans);     }     return 0;   }   