#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
vector<string> make_suffix_array(const &string s){
  vector<string> res;
  REP(i,(ll)s.size()+1){
    string tmp(s.begin()+i,s.end());
    res.push_back(tmp);
  }
  sort(ALL(res));
  return res;
}
int main(){//naive suffix array
  string t;
  int n;
  cin >> t >> n;
  auto suf = make_suffix_array(t);
  REP(i,n){
    string q;
    cin >> q;
    size_t sz = q.size();
    auto itr = lower_bound(ALL(suf),q);
    bool flag = false;
    do{
      if(itr==suf.end()) break;
      string cut(itr -> begin(),(itr->begin())+min(sz,itr->size()));
      if(cut==q){
        cout << 1 << endl;
        flag = true;
        break;
      } else if(cut > q){
        break;
      }
      ++itr;
    }while(true);
    if(!flag) cout << 0 << endl;
  }
}

