#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 2005;
using bit = bitset<MAX>;
bit basis[MAX];
bit solve[MAX];
int rk, n;
void insert(bit mask, int id = -1) {
  bit cur;
  if (id != -1) cur[id] = 1;
  for (int i = n - 1; i >= 0; i--)
    if (mask[i]) {
      if (basis[i] == 0) {
        basis[i] = mask, rk++;
        if (id != -1) solve[i] = cur;
        return;
      }
      mask ^= basis[i];
      if (id != -1) cur ^= solve[i];
    }
}
bit get(bit mask, bool rec = false) {
  bit ret = 0;
  for (int i = n - 1; i >= 0; i--)
    if (mask[i]) {
      if (basis[i] == 0) return bit(-1);
      mask ^= basis[i];
      if (rec)
        ret ^= solve[i];
      else
        ret[i] = 1;
    }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int m;
    cin >> n >> m;
    vector<bit> M(n);
    vector<int> dg(n);
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      dg[a]++, dg[b]++;
      M[a][b] = 1;
      M[b][a] = 1;
    }
    bool unique = true;
    for (int i = 0; i < n; i++)
      if (dg[i] % 2) M[i][i] = 1, unique = false;
    if (unique) {
      cout << 1 << '\n';
      for (int i = 0; i < n; i++) cout << 1 << " ";
      cout << '\n';
    } else {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) basis[i][j] = 0;
      rk = 0;
      bit y;
      for (int i = 0; i < n; i++) insert(M[i], i);
      for (int i = 0; i < n; i++) y[i] = dg[i] % 2;
      bit ret = get(y, 1);
      cout << 2 << '\n';
      for (int i = 0; i < n; i++) cout << ret[i] + 1 << " ";
      cout << '\n';
    }
  }
  exit(0);
}
