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

namespace ConsoleApplication1
{
    struct Pattern
    {
        internal string str;
        internal int id;
        internal bool find;
    }

    class SearchString
    {
        readonly int MOD = 1000000007;
        readonly int C = 407;

        public void SearchStrings(string text, Pattern[] patterns)
        {
            Array.Sort(patterns, (a, b) => a.str.Length - b.str.Length);

            int curLen = 0;
            long[] txtTable = new long[text.Length];
            long[] patTable;

            for (int i = 0; i < patterns.Length; i++)
            {
                string pat = patterns[i].str;

                if (pat.Length > text.Length) continue;

                if (curLen != pat.Length)
                {
                    txtTable = GenHash(text, text.Length, pat.Length);
                    curLen = pat.Length;
                }

                patTable = GenHash(pat, pat.Length, pat.Length);

                for (int j = 0; j <= text.Length - pat.Length; j++)
                {
                    if (txtTable[j] == patTable[0])
                    {
                        if (text.Substring(j, pat.Length) == pat)
                        {
                            patterns[i].find = true;
                            break;
                        }
                    }
                }
            }

            Array.Sort(patterns, (a, b) => a.id - b.id);

            StringBuilder sb = new StringBuilder();

            foreach (var p in patterns)
            {
                sb.AppendLine(p.find ? "1" : "0");
            }
            Console.Write(sb);
        }

        private long[] GenHash(string v, int n, int m)
        {
            long[] ret = new long[n];

            long cn = 1;

            for (int i = 0; i < m; i++) cn = (cn * C) % MOD;

            long hs = 0;

            for (int i = 0; i < m; i++) hs = (hs * C + v[i]) % MOD;

            for (int i = 0; i <= n - m; i++)
            {
                ret[i] = hs;

                if (i + m < n) hs = (hs * C - v[i] * cn + v[i + m]) % MOD;

                hs = (hs < 0) ? hs + MOD : hs;
            }
            return ret;
        }
    }

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

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

            Pattern[] patterns = new Pattern[Q];
            Pattern temp;

            for (int i = 0; i < Q; i++)
            {
                temp.str = Console.ReadLine();
                temp.id = i;
                temp.find = false;

                patterns[i] = temp;
            }

            SearchString SS = new SearchString();
            SS.SearchStrings(text, patterns);
        }
    }
}