#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<long long> d(k), a(k);

    for(int i = 0; i < k; i++){
        cin >> d[i];
        a[i] = d[i];
    }

    sort(a.begin(), a.end());

    map<long long, long long> m;
    m[1] = 1;
    m[2] = 3;
    m[3] = 2;
    m[4] = 7;

    for(int i = 1; i < k; i++){
        int br = a[i];
        bool b = true;
        for(int j = 2; j*j <= br; j++){
            int c = 0;
            while(br%j == 0){
                br /= j;
                c++;
            }

            if(c >= 1 && br > 1){
                m[a[i]] = m[a[i]/br]*m[br];
                b = false;
                break;
            }
            else if(br == 1){
                m[a[i]] = m[a[i]/j]^a[i];
                b = false;
                break;
            }
        }

        if(b) m[a[i]] = 1^a[i];
    }

    for(int i = 0; i < k; i++){
        cout << m[d[i]] << " ";
    }

    return 0;
}