#include <bits/stdc++.h>
using namespace std;
int input() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '0', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, m, du[2100];
bool Check() {
  for (int i = 1; i <= n; i++) {
    if (du[i] % 2 == 1) return 0;
  }
  printf("1\n");
  for (int i = 1; i < n; i++) printf("1 ");
  printf("1\n");
  return 1;
}
bitset<2100> s[2100];
void Gauss() {
  int x = 1;
  for (int j = 1; j <= n; j++) {
    for (int i = x; i <= n; i++) {
      if (s[i][j] == 1) {
        swap(s[i], s[x]);
        break;
      }
    }
    if (s[x][j] == 0) continue;
    for (int i = 1; i <= n; i++) {
      if (i == x) continue;
      if (s[i][j] == 1) s[i] ^= s[x];
    }
    x++;
  }
}
int as[2100];
void Solve() {
  int x, y;
  n = input(), m = input();
  for (int i = 1; i <= n; i++) s[i].reset();
  memset(du, 0, sizeof du);
  for (int i = 1; i <= m; i++) {
    x = input(), y = input();
    du[x]++, du[y]++;
    s[x][y] = 1, s[y][x] = 1;
  }
  if (Check()) return;
  for (int i = 1; i <= n; i++) {
    if (du[i] % 2 == 1) s[i][i] = 1, s[i][n + 1] = 1;
  }
  Gauss();
  x = 1;
  for (int j = 1; j <= n; j++) {
    if (s[x][j] == 0) {
      as[j] = 1;
      continue;
    }
    as[j] = s[x][n + 1] + 1;
    x++;
  }
  printf("2\n");
  for (int i = 1; i < n; i++) printf("%d ", as[i]);
  printf("%d\n", as[n]);
}
int main() {
  int T;
  T = input();
  while (T--) {
    Solve();
  }
}
