#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
#include <array>
#include <functional>
#include <stack>
#include <memory>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define x first
#define y second
#define Time (double)clock()/CLOCKS_PER_SEC
#define munq(a) sort(all(a)); a.resize(unique(all(a))-a.begin())
#define sz(a) ((int)a.size())

#ifdef LOCAL
#define debug(...) [](auto...a){ ((cerr << a << ' '), ...) << endl; }(#__VA_ARGS__, ":", __VA_ARGS__)
#else
#define debug(...)
#endif

#define FORI(i,a,b) for (int i = (a); i < (b); ++i)
#define FOR(i,a) FORI(i,0,a)
#define ROFI(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ROF(i,a) ROFI(i,0,a)
#define rep(a) FOR(_,a)
#define each(a,x) for (auto& a: x)
#define FORN(i, n) FORI(i, 1, n + 1)

using vi = vector<int>;
template <typename T>
std::istream& operator >>(std::istream& input, std::pair <T, T> & data)
{
    input >> data.x >> data.y;
    return input;
}
template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& data)
{
    for (T& x : data)
        input >> x;
    return input;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const pair <T, T> & data)
{
    output << "(" << data.x << "," << data.y << ")";
    return output;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const std::vector<T>& data)
{
    for (const T& x : data)
        output << x << " ";
    return output;
}
ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down 
ll math_mod(ll a, ll b) { return a - b * div_down(a, b); }
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>; 
tcT> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; 
} // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; 
}
tcT> vector <T> presum(vector <T> &a) {
    vector <T> p(a.size() + 1);
    FOR (i, a.size()) {
        p[i + 1] = p[i] + a[i];
    }   
    return p;
}
tcT> vector <T> sufsum(vector <T> &a) {
    vector <T> p(a.size() + 1);
    for (int i = (int)a.size() - 1; i >= 0; --i) {
        p[i] = p[i + 1] + a[i];
    }
    return p;
}
ll gcd(ll a, ll b) {
    while (b) {
        tie(a, b) = mp(b, a % b);
    }
    return a;
}
int Bit(int mask, int bit) { return (mask >> bit) & 1; }
struct Dsu {
int n;
vector <int> par, cnt;
Dsu (int n_) {
    n = n_;
    par.resize(n + 1);
    cnt.resize(n + 1, 1);
    FOR (i, n + 1) {
        par[i] = i;
    }
}   
int root(int u) {
    if (par[u] == u) {
        return u;
    }
    else {
        return par[u] = root(par[u]);                
    }
}   
void mergefast(int u, int v) {
    if (cnt[v] < cnt[u]) {
        swap(u, v);
    }
    par[u] = v;
    cnt[v] += cnt[u];
}
bool merge(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) {
        return 0;
    }
    if (cnt[v] < cnt[u]) {
        swap(u, v);
    }
    par[u] = v;
    cnt[v] += cnt[u];
    return 1;
}
};  
signed main() {
    #ifdef LOCAL
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    auto solve = [&] () {
    	int n, m;
    	cin >> n >> m;

    	debug(n,m);

    	vector <vector <int> > g(n), tree(n);
    	for (int i = 0; i < m; ++i) {
    		int u, v;
    		cin >> u >> v;
    		u--; v--;
    		g[u].app(v); g[v].app(u);
    	}

    	if (n & 1) {
    		cout << "-1\n";
    		return;
    	}

    	vector <int> ans(n, 1), used(n), cnt(n), par(n);
    	vector <pair <int, int> > e;
    	queue <int> q;
    	q.push(0);
    	mt19937 rnd(2007);
    	int num = 0, color = 2;
    	while (!q.empty()) {
    		int s = q.front();
    		q.pop();

    		num++;
    		vector <int> comp;
    		function <void(int)> dfs = [&] (int u) {
    			comp.app(u);
    			used[u] = num;
    			for (int v : g[u]) {
    				if (used[v] < num) {
    					dfs(v);
    				}
    			}
    		};
    		dfs(s);

    		bool ok = true;
    		for (int u : comp) {
    			ok &= g[u].size() % 2 == 1;
    		}
    		if (ok) {
    			continue;
    		}

    		e.clear();
    		for (int u : comp) {
    			for (int v : g[u]) {
    				if (u < v) {
    					e.app({u,v});
    				}
    			}
    		}
    		shuffle(all(e), rnd);

    		assert(comp.size() % 2 == 0);
    		sort(all(comp));
    		Dsu d(comp.size());
    		for (int u : comp) {
    			tree[u].clear();
    		}
    		for (auto [u, v] : e) {
    			int i = lower_bound(all(comp), u) - comp.begin();
    			int j = lower_bound(all(comp), v) - comp.begin();
    			if (d.root(i) != d.root(j)) {
    				d.merge(i, j);
    				tree[u].app(v);
    				tree[v].app(u);
    			}
    		}

    		vector <int> in;
    		function <void(int,int)> calc = [&] (int u, int p) {
    			par[u] = p;
    			in.app(u);
    			cnt[u] = 1;
    			for (int v : tree[u]) {
    				if (v != p) {
    					calc(v, u);
    					cnt[u] += cnt[v];
    				}
    			}
    		};
    		q.push(s);
    		calc(s, s);

    		for (int u : in) {
    			if (u != s && cnt[u] % 2 == 0) {
    				q.push(u);
    				ans[u] = color++;
    			}
    			else {
    				ans[u] = ans[par[u]];
    			}
    		}

    		for (int u : comp) {
    			vector <int> ng;
				for (int v : g[u]) {
					if (ans[u] == ans[v]) {
						ng.app(v);
					}
				}
				g[u] = ng;
    		}
    	}

    	cout << ans << '\n';
    };
    int t;
    cin >> t;
    rep (t) {
        solve();
    }
}