#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, ans[N], h[N];
bitset<N> a[N];
vector<int> e[N];
bool check1() {
  for (int i = (int)(1); i <= (int)(n); i++)
    if (e[i].size() & 1) return 0;
  return 1;
}
void gauss() {
  int it = 1;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int j = it;
    for (; j <= n; j++)
      if (a[j][i]) break;
    if (j > n) continue;
    if (j > it) swap(a[j], a[it]);
    h[it] = i;
    for (int j = (int)(it + 1); j <= (int)(n); j++)
      if (a[j][i]) a[j] ^= a[it];
    it++;
  }
  int las = n + 1;
  for (int i = (int)(it - 1); i >= (int)(1); i--) {
    for (int j = (int)(h[i] + 1); j <= (int)(las - 1); j++) ans[j] = 0;
    ans[h[i]] = a[i][0];
    for (int j = (int)(1); j <= (int)(i - 1); j++)
      if (a[j][h[i]]) a[j] ^= a[i];
    las = h[i];
  }
  for (int i = (int)(1); i <= (int)(las - 1); i++) ans[i] = 0;
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(1); i <= (int)(n); i++) e[i].clear();
  for (int i = (int)(1); i <= (int)(m); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  if (check1()) {
    puts("1");
    for (int i = (int)(1); i <= (int)(n); i++) printf("1 ");
    puts("");
    return;
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    a[i] = 0;
    for (auto j : e[i]) a[i].set(j);
    if (e[i].size() & 1) a[i].set(i), a[i].set(0);
  }
  memset(ans, 0, sizeof(ans));
  gauss();
  puts("2");
  for (int i = (int)(1); i <= (int)(n); i++) printf("%d ", ans[i] + 1);
  puts("");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
}
