#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[2010];
bitset<2010> bt[2010];
void init() {
  memset(d, 0, sizeof(d));
  for (int i = 0; i < n; ++i) {
    bt[i].reset();
  }
}
void guss() {
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      if (bt[j][i]) {
        swap(bt[j], bt[i]);
        break;
      }
    }
    if (!bt[i][i]) {
      continue;
    }
    for (int j = 0; j < n; ++j) {
      if (j ^ i && bt[j][i]) {
        bt[j] ^= bt[i];
      }
    }
  }
}
int main() {
  int c;
  scanf("%d", &c);
  ;
  ;
  while (c--) {
    scanf("%d%d", &n, &m);
    ;
    ;
    init();
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      ;
      ;
      bt[a][b] = 1;
      bt[b][a] = 1;
      d[a] ^= 1;
      d[b] ^= 1;
    }
    int ret = 0;
    for (int i = 0; i < n; ++i) {
      ;
      ;
      if (d[i]) {
        ret = 1;
        bt[i][i] = 1;
        bt[i][n] = 1;
      }
    }
    if (ret == 0) {
      ;
      ;
      cout << 1 << endl;
      for (int i = 0; i < n; ++i) {
        cout << 1 << " ";
      }
      cout << endl;
      continue;
    }
    guss();
    cout << 2 << endl;
    for (int i = 0; i < n; ++i) {
      cout << bt[i][n] + 1 << " ";
    }
    cout << endl;
  }
}
