using System;
using System.Text;
using System.IO;

namespace ALDS1_14_D
{
	class SuffixArray
	{
		internal int[] sa, rank, tmp;
		internal string S;
		internal int n, k;
		
		public SuffixArray(string SS)
		{
			S = SS;
			n = S.Length;
			sa = new int[n + 1];
			rank = new int[n + 1];
			tmp = new int[n + 1];
			Construct_SA();
		}
		
		public int Compare_SA(int i, int j)
		{
			if(rank[i] != rank[j]) return rank[i] - rank[j];
			
			int ri = i + k  <= n ? rank[i + k] : -1;
			int rj = j + k <= n ? rank[j + k] : -1;

			return  ri - rj; 
		}
		
		public void Construct_SA()
		{
			for(int i = 0; i < n; i++)
			{
				sa[i] = i;
				rank[i] = S[i];
			}
			sa[n] = n; rank[n] = -1;
			
			for(k = 1; k <= n; k*= 2)
			{
				Array.Sort(sa, Compare_SA);
                
                int d;
                d = tmp[sa[0]] = 0;
                for (int i = 1; i <= n; i++)
                {
                    d = tmp[sa[i]] = d + ((Compare_SA(sa[i - 1], sa[i]) < 0) ? 1 : 0);
                }
                for (int i = 0; i <= n; i++)
                {
                    rank[i] = tmp[i];
                }
 
			}
		}
		
		public string Contains(string pattern)
		{
			int l = 1, r = n + 1;
			int pl = pattern.Length;
			
			while(l < r)
			{
				int m = (l + r) / 2;
				
				string subStr = (sa[m] + pl > n) ? S.Substring(sa[m]) : S.Substring(sa[m], pl);
                    
                int comp = subStr.CompareTo(pattern);
                if (comp == 0) return "1";
                
                if (comp < 0) l = m + 1;
                else r = m;
			}
			return "0";
		}
	}
	
	
    class Program
    {
    	
        static void Main(string[] args)
        {
        	var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    	 	Console.SetOut(sw);
    	 
        	var T = Console.ReadLine();
        	
            SuffixArray SA = new SuffixArray(T);
            StringBuilder sb = new StringBuilder();
 
            var Q = int.Parse(Console.ReadLine());
 
            for (int i = 0; i < Q; i++)
            {
                var P = Console.ReadLine();
 
                Console.WriteLine(SA.Contains(P));
            }
            Console.Out.Flush();
        }
    }
}