#include <bits/stdc++.h>
 
using namespace std;

#define MAX 1000000
 
int n,k,sa[MAX];
int rank[MAX],tmp[MAX];
 
bool compare_sa(int i,int j){
    if(rank[i] != rank[j]){
        return rank[i] < rank[j];
    }else{
        int ri = i + k <= n ? rank[i+k] : -1;
        int rj = j + k <= n ? rank[j+k] : -1;
        return ri < rj;
    }
}

void construct_sa(string &S,int *sa){
    n = S.length();
   
    for(int i = 0 ; i <= n ; i++){
        sa[i] = i;
        rank[i] = i < n ? S[i] : -1;
    }
 
    for(k = 1 ; k <= n ; k *= 2){
        sort(sa,sa+n+1,compare_sa);
     
        tmp[sa[0]] = 0;
        for(int i = 1 ; i <= n ; i++){
            tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1],sa[i]) ? 1 : 0);
        }
        for(int i = 0 ; i <= n ; i++){
            rank[i] = tmp[i];
        }
    }
}
 
bool contain(string &S,int *sa,string &T){
    int a = 0, b = S.length();
    while(b - a > 1){
        int c = (a + b ) / 2;
        if(S.compare(sa[c],T.length(),T) < 0) a = c;
        else b = c;
    }
    return S.compare(sa[b],T.length(),T) == 0;
}
 
int main(){
    int Q;
    string S,T;
    cin >> S >> Q;
    construct_sa(S,sa);
    while(Q--){
        cin >> T;
        if(S.size() < T.size()){ puts("0"); continue; }
        puts(contain(S,sa,T) ? "1" : "0");
    }
    return 0;
}