#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdint>

#define let auto
#define fn auto
#define usize size_t
using u32 = uint32_t;
using namespace std;

const u32 KX = 123456789;
const u32 KY = 362436069;
const u32 KZ = 521288629;
const u32 KW = 88675123;

fn fastio() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

struct Rand {
    u32 x, y, z, w;

    static Rand new_seed(u32 seed) {
        return {KX ^ seed, KY ^ seed, KZ, KW};
    }

    u32 rand() {
        u32 t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        w ^= (w >> 19) ^ t ^ (t >> 8);
        return w;
    }

    template<typename T>
    void shuffle(vector<T>& a) {
        if (a.empty()) return;
        usize i = a.size() - 1;
        while (i > 0) {
            usize j = rand() % (i + 1);
            swap(a[i], a[j]);
            i--;
        }
    }

    u32 rand_range(u32 a, u32 b) {
        u32 m = b - a + 1;
        return a + rand() % m;
    }

    double rand_float() {
        return static_cast<double>(rand()) / static_cast<double>((u32)-1);
    }
};

fn main() -> int {
    fastio();

    istreambuf_iterator<char> it(cin), end;
    string temp(it, end);
    vector<u32> vals;
    usize pos = 0;
    while (pos < temp.size()) {
        while (pos < temp.size() && isspace(temp[pos])) pos++;
        if (pos >= temp.size()) break;
        usize start = pos;
        while (pos < temp.size() && !isspace(temp[pos])) pos++;
        vals.push_back(stoul(temp.substr(start, pos - start)));
    }

    auto it2 = vals.begin();
    u32 n = *it2++;
    u32 m = *it2++;

    vector<tuple<u32, u32, u32, u32, u32>> requests;
    for (u32 i = 0; i < m; i++) {
        u32 w = *it2++ - 1;
        u32 x = *it2++ - 1;
        u32 y = *it2++ - 1;
        u32 z = *it2++ - 1;
        u32 k = *it2++;
        requests.emplace_back(w, x, y, z, k);
    }

    u32 trial = 0;
    while (true) {
        Rand rand = Rand::new_seed(trial);
        vector<u32> music(n);
        for (u32 i = 0; i < n; i++) {
            music[i] = rand.rand_range(0, 3);
        }

        u32 cnt = 0;
        for (const auto& req : requests) {
            u32 w, x, y, z, k;
            tie(w, x, y, z, k) = req;
            if ((music[w] + music[x] + music[y] + music[z]) % 4 == k) {
                cnt++;
            }
        }
        if (m / 4 <= cnt) {
            for (u32 a : music) {
                cout << a << ' ';
            }
            break;
        }
        trial++;
    }
    return 0;
}