using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;

namespace ConsoleApp1
{
    internal class Program
    {
        static List<int> delioci(int a)
        {
            List<int> n = new List<int>();
            int delilac = 2;
            int d3 = 3;
            while (delilac <= a)
            {
                if (a % delilac == 0 && delilac != 0 && n.Contains(delilac) == false)
                {
                    if (n.Contains(delilac) == false)
                    {
                        n.Add(delilac);
                    }
                   
                    if (n.Contains(a / delilac) == false)
                    {
                        n.Add(a / delilac);
                    }

                }
                else if(a % d3 == 0 && d3 != 0 && n.Contains(d3) == false){
                    if (n.Contains(d3) == false)
                    {
                        n.Add(d3);
                    }
                    if (n.Contains(a / d3) == false)
                    {
                        n.Add(a / d3);
                    }
                }

                delilac *= 2;
                d3 *= 3;

            }
            return n;


        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int q = int.Parse(s[1]);
            int[] x = new int[n];
            List<int>kraj=new List<int>();  
            string[] s1 = Console.ReadLine().Split(' ');

            for (int i = 0; i < q; i++)
            {
                int w = 0;
                int br = 0;
                x[i] = int.Parse(s1[i]);
                List<int> l = new List<int>();
                l = delioci(x[i]);
                if (l.Contains(x[i]) == false)
                    l.Add(x[i]);
                if (l.Contains(1) == false)
                {
                    l.Add(1);
                }
                l.Sort();
                for (int j = 0; j < l.Count(); j++)
                {
                    w = w ^ l[j];
                }
                if (w == 0)
                {
                    w = 1;
                }
                kraj.Add(w);               


            }
            for (int i = 0; i < q; i++) {
                Console.Write(kraj[i] + " ");
            }
            Console.WriteLine();







        }
    }
}