#include <bits/stdc++.h>
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
long long max(long long a, int b) { return max(a, long long(b)); }
long long max(int a, long long b) { return max(long long(a), b); }
long long min(long long a, int b) { return min(a, long long(b)); }
long long min(int a, long long b) { return min(long long(a), b); }
struct RollingHash {
  vector<unsigned long long> hash, pow;
  RollingHash(string s, unsigned long long _b = 1000000007) {
    _b = _b;
    int sz = s.length();
    hash.assign(sz + 1, 0);
    pow.assign(sz + 1, 0);
    pow[0] = 1;
    for (int i = 0; i < sz; i++) {
      pow[i + 1] = pow[i] * _b;
    }
    for (int i = 0; i < sz; i++) {
      hash[i + 1] = (hash[i] + s[i]) * _b;
    }
  }
  unsigned long long get(int l, int r) {
    return (hash[r] - hash[l] * pow[r - l]);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string t;
  cin >> t;
  RollingHash rht(t);
  int q;
  cin >> q;
  vector<set<unsigned long long>> st(1000);
  for (long long i = 0; i < long long(q); ++i) {
    string p;
    cin >> p;
    RollingHash rh(p);
    if (p.size() > t.size()) {
      cout << 0 << endl;
      continue;
    }
    if (st[p.size() - 1].size() == 0) {
      for (long long j = 0; j < long long(t.size() - p.size() + 1); ++j) {
        st[p.size() - 1].insert(rht.get(j, j + p.size()));
      }
    }
    cout << st[p.size() - 1].count(rh.get(0, p.size())) << "\n";
  }
}
