#include <bits/stdc++.h>
using namespace std;
inline int cti(char x) { return x - 'a'; }
typedef class TrieNode {
 public:
  TrieNode* next[26];
  TrieNode* fail;
  vector<TrieNode*> son;
  int cnt;
  int len;
  int t;
  TrieNode() : fail(NULL), cnt(0), len(0), t(2333333) {
    memset(next, 0, sizeof(next));
  }
} TrieNode;
typedef class SuffixAutomachine {
 public:
  TrieNode* pool;
  TrieNode* top;
  TrieNode* root;
  TrieNode* last;
  TrieNode* newnode() { return top++; }
  TrieNode* newnode(int len) {
    top->len = len;
    return top++;
  }
  SuffixAutomachine() : pool(NULL), top(NULL), root(NULL), last(NULL) {}
  SuffixAutomachine(int len) {
    pool = new TrieNode[len * 2 + 5];
    top = pool;
    root = newnode();
    last = root;
  }
  inline void extend(char x) {
    int c = cti(x);
    TrieNode *node = newnode(last->len + 1), *f = last;
    node->cnt = 1;
    while (f && f->next[c] == NULL) f->next[c] = node, f = f->fail;
    if (f == NULL)
      node->fail = root;
    else {
      TrieNode* p = f->next[c];
      if (p->len == f->len + 1)
        node->fail = p;
      else {
        TrieNode* clone = newnode(f->len + 1);
        memcpy(clone->next, p->next, sizeof(clone->next));
        clone->fail = p->fail;
        p->fail = clone;
        node->fail = clone;
        while (f && f->next[c] == p) f->next[c] = clone, f = f->fail;
      }
    }
    last = last->next[c];
  }
} SuffixAutomachine;
int lens;
int n;
char str[2000005];
SuffixAutomachine sam;
inline void init() {
  gets(str);
  lens = strlen(str);
}
int dfs(TrieNode* p) {
  for (int i = 0; i < (signed)p->son.size(); i++) p->cnt += dfs(p->son[i]);
  return p->cnt;
}
inline void init_sam() {
  sam = SuffixAutomachine(lens);
  for (int i = 0; i < lens; i++) sam.extend(str[i]);
  for (TrieNode* p = sam.pool; p != sam.top; p++) {
    if (p->fail) p->fail->son.push_back(p);
  }
  dfs(sam.root);
}
inline void solve() {
  scanf("%d", &n);
  gets(str);
  while (n--) {
    gets(str);
    lens = strlen(str);
    memcpy(str + lens, str, sizeof(char) * (lens - 1));
    TrieNode *p = sam.root, *q;
    int res = 0;
    for (int i = 0, nlen = 0, c; i < 2 * lens - 1 && p; i++) {
      c = cti(str[i]);
      if (!p->next[c]) {
        while (p && !p->next[c]) p = p->fail, nlen = (p) ? (p->len) : (0);
        if (!p) break;
      }
      p = p->next[c], nlen++;
      if (nlen >= lens) {
        q = p;
        while (q->fail->len >= lens) q = q->fail;
        if (q->t != n) {
          res += q->cnt;
          q->t = n;
        }
      }
    }
    printf("%d\n", res);
  }
}
int main() {
  init();
  init_sam();
  solve();
  return 0;
}
