#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int n;
bitset<N> a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int m;
    cin >> n >> m;
    for (int i = 0; i < (int)(n); i++) a[i] = 0;
    while (m--) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      a[u].set(v);
      a[v].set(u);
      a[u].flip(n);
      a[v].flip(n);
    }
    for (int i = 0; i < (int)(n); i++) a[i][i] = a[i][n];
    bool odd = false;
    for (int i = 0; i < (int)(n); i++) odd |= a[i][n];
    if (!odd) {
      cout << 1 << '\n';
      for (int i = 0; i < (int)(n); i++) cout << "1 ";
      cout << '\n';
      continue;
    }
    vector<int> good;
    for (int col = 0; col < (int)(n); col++) {
      int row = ((int)(good).size());
      for (int i = (int)(row); i < ((int)n); i++)
        if (a[i][col]) {
          swap(a[row], a[i]);
          break;
        }
      if (!a[row][col]) continue;
      good.push_back(col);
      for (int i = 0; i < (int)(n); i++)
        if (i != row && a[i][col]) a[i] ^= a[row];
    }
    vector<int> ans(n);
    for (int i = 0; i < (int)(((int)(good).size())); i++)
      ans[good[i]] = a[i][n];
    cout << "2\n";
    for (auto x : ans) cout << x + 1 << ' ';
    cout << '\n';
  }
  return 0;
}
