#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x),end(x)
#define sz(x) int(x.size())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
void solve() {
    int n,m; cin >> n >> m;
    vvi adj(n);
    for(int i=0;i<m;++i) {
        int u,v; cin >> u >> v;
        --u,--v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(n%2==1) {
        cout << "-1\n";
        return;
    }

    vi d(n);
    vi s(n);
    vi ans(n);
    vector<bool> vis(n),placed(n);
    vvi backes(n);
    int col=1;
    int atleast;
    auto dfs2 = [&](auto&& self, int at) -> void {
        if(d[at]<atleast) return;
        placed[at]=1;
        ans[at]=col;
        for(int to : adj[at]) {
            if(vis[to] and !placed[to]) {
                self(self,to);
            }
        }
    };
    auto dfs = [&](auto&& self, int at, int from) -> void {
        s[at]+=1;
        vis[at]=1;

        for(int to : adj[at]) if(to!=from) {
            if(!vis[to]) {
                d[to]=d[at]+1;
                self(self,to,at);
                s[at]+=s[to];
            } else if(d[to]>d[at]) {
                if(not placed[to]) {
                    s[at]+=s[to];
                }
            } else {
                backes[at].push_back(to);
            }
        }
        if(s[at]%2==0) {
            // split dit allemaal
            atleast=d[at];
            dfs2(dfs2,at);
            s[at]=0;
            col++;
        } else {
            for(int to : adj[at]) if(d[to]>d[at]) {
                if(!placed[to]) {
                    while(!backes[to].empty() and d[backes[to].back()]>=d[at]) {
                        backes[to].pop_back();
                    }
                    if(!backes[to].empty()) {
                        s[at]-=s[to];
                        placed[to]=1;
                        atleast=d[at];
                        dfs2(dfs2,at);
                        placed[to]=0;
                        s[at]=0;
                        col++;
                        break;
                    }
                }
            }
        }
        sort(all(backes[at]),[&](int i, int j) {return d[i]<d[j];});
    };
    dfs(dfs,0,-1);
    for(auto i : ans) cout << i << ' ';
    for(int at=0;at<n;++at) {
        int num=1;
        for(int to : adj[at]) {
            num+=ans[at]==ans[to];
        }
        assert(num%2==0);
    }
    cout << '\n';
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t; cin >> t;
    while(t--) solve();
}