#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const long long mo = (long long)1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bitset<2100> gauss[2100];
int ans[2100];
void work() {
  int n, m;
  cin >> n >> m;
  int x, y;
  for (int i = 1; i <= n; i++) {
    gauss[i].reset();
    gauss[i][i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    gauss[x][n + 1] = gauss[x][n + 1] ^ 1;
    gauss[y][n + 1] = gauss[y][n + 1] ^ 1;
    gauss[x][y] = gauss[y][x] = 1;
  }
  bool flag = 1;
  for (int i = 1; i <= n; i++) {
    if (gauss[i][n + 1]) {
      flag = 0;
      break;
    }
  }
  if (flag) {
    cout << "1\n";
    for (int i = 1; i <= n; i++) {
      cout << 1 << " \n"[i == n];
    }
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (!gauss[i][n + 1]) {
      gauss[i][i] = 0;
    }
  }
  int now = 1;
  for (int i = 1; i <= n; i++) {
    int j = now;
    while (j <= n && !gauss[j][i]) j++;
    if (j > n) {
      ans[i] = 0;
      for (int k = 1; k < now; ++k) {
        gauss[k][i] = 0;
      }
      continue;
    }
    if (j != now) {
      swap(gauss[j], gauss[now]);
    }
    while (++j <= n) {
      if (gauss[j][i]) {
        gauss[j] ^= gauss[now];
      }
    }
    ++now;
  }
  for (int j = now - 1; j; --j) {
    int p = 0;
    for (int k = 1; !p && k <= n; ++k) {
      if (gauss[j][k]) p = k;
    }
    ans[p] = gauss[j][n + 1];
    for (int k = j - 1; k; --k) {
      if (gauss[k][p]) {
        gauss[k] ^= gauss[j];
      }
    }
  }
  cout << "2\n";
  for (int i = 1; i <= n; i++) {
    cout << ans[i] + 1 << " \n"[i == n];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) work();
  return 0;
}
