#include <bits/stdc++.h>
using namespace std;
const unsigned long long int B = 1e9 + 7;
bool contain(string s, string a) {
  int sl = s.length(), al = a.length();
  if (sl < al) return false;
  unsigned long long int t = 1;
  for (int i = 0; i < al; i++) t *= B;
  unsigned long long int sh = 0, ah = 0;
  for (int i = 0; i < al; i++) {
    sh = sh * B + s[i];
    ah = ah * B + a[i];
  }
  if (sh == ah) return true;
  for (int i = 0; i + al < sl; i++) {
    sh = sh * B + s[i + al] - s[i] * t;
    if (sh == ah) return true;
  }
  return false;
}
vector<int> match(string s, string a) {
  int sl = s.length(), al = a.length();
  vector<int> ans;
  if (sl < al) return ans;
  unsigned long long int t = 1;
  unsigned long long int ah = 0, sh = 0;
  for (int i = 0; i < al; i++) {
    sh = sh * B + s[i];
    ah = ah * B + a[i];
    t *= B;
  }
  if (sh == ah) ans.push_back(0);
  for (int i = 0; i + al < sl; i++) {
    sh = sh * B + s[i + al] - s[i] * t;
    if (sh == ah) ans.push_back(i + 1);
  }
  return ans;
}
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  string a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cout << contain(s, a) << endl;
  }
  return 0;
}
