#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,k;
vector<ll> Rank;
vector<ll> tmp;
vector<ll> sa;
string str;


bool less_cmp(ll a,const string &s){
    for(ll i=0;i<s.size();i++){
        if(i+a>=n){return true;}
        if(str[i+a]!=s[i]){return str[i+a]<s[i];}
    }
    return false;
}

bool equal_cmp(ll a,const string &s){
    for(ll i=0;i<s.size();i++){
        if(i+a>=n){return false;}
        if(str[i+a]!=s[i]){return false;}
    }
    return true;
}

bool cmp(ll i,ll j){
    if(Rank[i]!=Rank[j]){return Rank[i]<Rank[j];}
    return (i+k<=n?Rank[i+k]:-1)<(j+k<=n?Rank[j+k]:-1);
}

void build(const string &s){
    n=s.size();
    sa.resize(n+1);
    Rank.resize(n+1);
    tmp.resize(n+1);
    for(int i=0;i<=n;i++){
        sa[i]=i;
        Rank[i]=i<n?s[i]:-1;
    }
    for(k=1;k<=n;k<<=1){
        sort(sa.begin(),sa.end(),cmp);
        tmp[sa[0]]=0;
        for(int i=1;i<=n;i++){
            tmp[sa[i]]=tmp[sa[i-1]]+(cmp(sa[i-1],sa[i])?1:0);
        }
        for(int i=0;i<=n;i++){
            Rank[i]=tmp[i];
        }
    }
}


bool search(const string &s){
    ll l=0,r=n;
    while(r-l>=10){
        ll m=l+(r-l)/2;
        if(less_cmp(sa[m],s)){l=m+1;}
        else{r=m;}
    }
    for(ll i=l;i<=r;i++){
        if(equal_cmp(sa[i],s)){return true;}
    }
    return false;
}




int main(){
    cin>>str;
    build(str);
    /*
    cout<<endl;
    for(int i=0;i<=str.size();i++){
        cout<<i<<" "<<Rank[sa[i]]<<endl;
        for(ll t=sa[i];t<str.size();t++){cout<<str[t];}
        cout<<endl;
    }
     */
    ll q;
    cin>>q;
    while(q--){
        string p;
        cin>>p;
        cout<<search(p)<<endl;
    }
    
    
    return 0;
}


### Prompt

Develop a solution in cpp to the problem described below:

Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.

Constraints

* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P_i ≤ 1000
* 1 ≤ Q ≤ 10000
* The input consists of alphabetical characters and digits

Input

In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.

Output

For each question, print 1 if the text includes P_i, or print 0 otherwise.

Example

Input

aabaaa
4
aa
ba
bb
xyz


Output

1
1
0
0

### Response

```cpp
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll n,k;
vector<ll> Rank;
vector<ll> tmp;
vector<ll> sa;
string str;


bool less_cmp(ll a,const string &s){
    for(ll i=0;i<s.size();i++){
        if(i+a>=n){return true;}
        if(str[i+a]!=s[i]){return str[i+a]<s[i];}
    }
    return false;
}

bool equal_cmp(ll a,const string &s){
    for(ll i=0;i<s.size();i++){
        if(i+a>=n){return false;}
        if(str[i+a]!=s[i]){return false;}
    }
    return true;
}

bool cmp(ll i,ll j){
    if(Rank[i]!=Rank[j]){return Rank[i]<Rank[j];}
    return (i+k<=n?Rank[i+k]:-1)<(j+k<=n?Rank[j+k]:-1);
}

void build(const string &s){
    n=s.size();
    sa.resize(n+1);
    Rank.resize(n+1);
    tmp.resize(n+1);
    for(int i=0;i<=n;i++){
        sa[i]=i;
        Rank[i]=i<n?s[i]:-1;
    }
    for(k=1;k<=n;k<<=1){
        sort(sa.begin(),sa.end(),cmp);
        tmp[sa[0]]=0;
        for(int i=1;i<=n;i++){
            tmp[sa[i]]=tmp[sa[i-1]]+(cmp(sa[i-1],sa[i])?1:0);
        }
        for(int i=0;i<=n;i++){
            Rank[i]=tmp[i];
        }
    }
}


bool search(const string &s){
    ll l=0,r=n;
    while(r-l>=10){
        ll m=l+(r-l)/2;
        if(less_cmp(sa[m],s)){l=m+1;}
        else{r=m;}
    }
    for(ll i=l;i<=r;i++){
        if(equal_cmp(sa[i],s)){return true;}
    }
    return false;
}




int main(){
    cin>>str;
    build(str);
    /*
    cout<<endl;
    for(int i=0;i<=str.size();i++){
        cout<<i<<" "<<Rank[sa[i]]<<endl;
        for(ll t=sa[i];t<str.size();t++){cout<<str[t];}
        cout<<endl;
    }
     */
    ll q;
    cin>>q;
    while(q--){
        string p;
        cin>>p;
        cout<<search(p)<<endl;
    }
    
    
    return 0;
}


```