#include <bits/stdc++.h>
using namespace std;
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() {
  string t;
  cin >> t;
  int q;
  cin >> q;
  RollingHash hash(t);
  unordered_set<unsigned long long> s;
  for (int i = 0; i < t.size(); i++) {
    for (int j = 0; j < min(1000, (int)t.size() - i); j++) {
      s.insert(hash.get(i, i + j + 1));
    }
  }
  for (int i = 0; i < q; i++) {
    string p;
    cin >> p;
    cout << s.count(RollingHash(p).get(0, p.size())) << endl;
  }
}
