#include <bits/stdc++.h>
using namespace std;
bitset<2005> a[2005];
int n, m, i, j, deg[2005], t, ans[2005], z[2005];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (i = 1; i <= n; i++) {
      a[i].reset();
      deg[i] = 0;
    }
    for (i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      deg[x]++;
      deg[y]++;
      a[x][n + 1] = a[x][n + 1] ^ 1;
      a[y][n + 1] = a[y][n + 1] ^ 1;
      a[x][y] = a[y][x] = 1;
    }
    bool f = 1;
    for (i = 1; i <= n; i++) {
      if (deg[i] & 1) {
        f = 0;
        a[i][i] = 1;
      }
    }
    if (f) {
      puts("1");
      for (i = 1; i <= n; i++) {
        printf("%d%c", 1, (i == n ? '\n' : ' '));
      }
      continue;
    }
    for (i = 1; i <= n; i++) {
      int t = -1;
      for (j = i; j <= n; j++) {
        if (a[j][i]) {
          t = j;
          break;
        }
      }
      if (t == -1) {
        for (j = 1; j < i; j++) a[j][i] = 0;
        ans[i] = 0;
        z[i] = 1;
        continue;
      }
      z[i] = 0;
      swap(a[i], a[t]);
      for (j = i + 1; j <= n; j++) {
        if (a[j][i]) a[j] ^= a[i];
      }
    }
    for (i = n; i >= 1; i--) {
      if (z[i]) continue;
      for (j = i + 1; j <= n; j++) {
        if (a[i][j]) a[i][n + 1] = a[i][n + 1] ^ ans[j];
      }
      ans[i] = a[i][n + 1];
    }
    puts("2");
    for (i = 1; i <= n; i++) {
      printf("%d%c", 1 + ans[i], (i == n ? '\n' : ' '));
    }
  }
  return 0;
}
