using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class KMP
    {
        int[] lps;

        public int IndexOf(string text, string pattern)
        {
            int M = pattern.Length;
            int N = text.Length;
            int i = 0;
            int j = 0;

            ComputeLPS(pattern, M);

            while (i < N)
            {
                if (pattern[j] == text[i])
                {
                    j++;
                    i++;
                }

                if (j == M)
                {
                    return (i - j);
                }

                else if (i < N && pattern[j] != text[i])
                {
                    if (j != 0) j = lps[j - 1];
                    else i++;
                }
            }
            return -1;
        }

        private void ComputeLPS(string pattern, int M)
        {
            lps = new int[M];
            lps[0] = 0;

            int len = 0;
            int i = 1;

            while (i < M)
            {
                if (pattern[i] == pattern[len])
                {
                    len++;
                    lps[i] = len;
                    i++;
                }
                else
                {
                    if (len != 0)
                    {
                        len = lps[len - 1];
                    }
                    else
                    {
                        lps[i] = 0;
                        i++;
                    }
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string text = Console.ReadLine();

            int n = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();
            KMP kmp = new KMP();

            for (int i = 0; i < n; i++)
            {
                string pattern = Console.ReadLine();

                int index = kmp.IndexOf(text, pattern);

                sb.AppendLine(index >= 0 ? "1" : "0");
            }
            Console.Write(sb);
        }
    }
}