#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int L = 1e6 + 5;
namespace SAM {
const int T = L << 1;
struct Node {
  map<char, int> ch;
  int link, len, size;
} t[T];
int last;
int total;
void extend_char(char c) {
  int p = last, np = last = ++total;
  t[np].len = t[p].len + 1;
  for (; p && !t[p].ch[c]; p = t[p].link) t[p].ch[c] = np;
  if (!p) {
    t[np].link = 1;
  } else {
    int q = t[p].ch[c];
    if (t[p].len + 1 == t[q].len) {
      t[np].link = q;
    } else {
      int nq = ++total;
      t[nq] = t[q], t[nq].len = t[p].len + 1, t[nq].size = 0;
      t[np].link = t[q].link = nq;
      for (; p && t[p].ch[c] == q; p = t[p].link) t[p].ch[c] = nq;
    }
  }
  t[np].size = 1;
}
int b[T], c[T];
void init_data(string& s) {
  last = total = 1;
  for (string::iterator it = s.begin(); it != s.end(); it++) extend_char(*it);
  for (register int i = 1; i <= total; i++) ++c[t[i].len];
  for (register int i = 1; i <= total; i++) c[i] += c[i - 1];
  for (register int i = 1; i <= total; i++) b[c[t[i].len]--] = i;
  for (register int i = total; i; i--) {
    int x = b[i], f = t[x].link;
    t[f].size += t[x].size;
  }
}
int vis[T];
long long count(string& str, int time);
};  // namespace SAM
long long SAM::count(string& str, int time) {
  long long ret = 0ll;
  int x = 1, len = 0;
  str = str + str;
  for (register int i = 0; i < str.size(); i++) {
    char c = str[i];
    while (x && !t[x].ch[c]) x = t[x].link, len = t[x].len;
    if (!x)
      x = 1, len = 0;
    else
      x = t[x].ch[c], len++;
    while (x && t[t[x].link].len >= str.size() / 2)
      x = t[x].link, len = t[x].len;
    if (len >= str.size() / 2 && vis[x] != time)
      ret += t[x].size, vis[x] = time;
  }
  return ret;
}
signed main() {
  ios::sync_with_stdio(false);
  string str;
  cin >> str;
  SAM::init_data(str);
  int m;
  cin >> m;
  for (register int time = 1; time <= m; time++) {
    cin >> str;
    cout << SAM::count(str, time) << endl;
  }
  return 0;
}
