#include <bits/stdc++.h>
using namespace std;
unsigned int B = 100000007;
int h[1001] = {};
vector<unsigned int> v[1001];
void contain(string b, int n) {
  int bl = b.size();
  unsigned int t = 1;
  for (int i = 0; i < n; i++) t *= B;
  unsigned int bh = 0;
  for (int i = 0; i < n; i++) bh = bh * B + b[i];
  for (int i = 0; i + n <= bl; i++) {
    v[n].push_back(bh);
    if (i + n < bl) bh = bh * B + b[i + n] - b[i] * t;
  }
  sort(v[n].begin(), v[n].end());
  return;
}
int main() {
  int n;
  string b;
  cin >> b >> n;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    int al = a.size();
    if (al > b.size()) {
      cout << '0' << endl;
      continue;
    }
    if (h[al] == 0) {
      contain(b, al);
      h[al] = 1;
    }
    unsigned int ah = 0;
    for (int j = 0; j < al; j++) ah = ah * B + a[j];
    int l = 0, m, r = v[al].size(), f = 0;
    while (r > l) {
      m = (l + r) / 2;
      if (v[al][m] == ah) {
        f = 1;
        break;
      } else if (v[al][m] > ah)
        r = m;
      else
        l = m + 1;
    }
    cout << f << endl;
  }
  return 0;
}
