#include <bits/stdc++.h>
using namespace std;
int T, n, m, head[100010], o, Vc, Ec, st[100010], t, deg[100010], f[100010],
    dep[100010], fa[100010];
bool vis[100010];
vector<int> vec;
vector<pair<int, int> > lf;
struct edge {
  int to, link;
} e[200010];
void add_edge(int u, int v) {
  deg[u]++, deg[v]++;
  e[++o].to = v, e[o].link = head[u], head[u] = o;
  e[++o].to = u, e[o].link = head[v], head[v] = o;
}
void dfs(int u, int pre) {
  vis[u] = true, Vc++, st[++t] = u;
  for (int i = head[u]; i; i = e[i].link)
    if (e[i].to != pre) {
      Ec++;
      if (vis[e[i].to]) continue;
      dfs(e[i].to, u);
    }
}
void dfs2(int u, int pre) {
  dep[u] = dep[pre] + 1, fa[u] = pre;
  if (e[head[u]].to == pre && !e[head[u]].link)
    lf.push_back(make_pair(dep[u], u));
  for (int i = head[u]; i; i = e[i].link)
    if (e[i].to != pre) {
      dfs2(e[i].to, u);
    }
}
bool work(int u, int pre, int v) {
  if (u == v) return f[u] = 2, true;
  for (int i = head[u]; i; i = e[i].link)
    if (e[i].to != pre) {
      if (work(e[i].to, u, v)) {
        return f[u] = 2, true;
      }
    }
  return false;
}
void solve() {
  scanf("%d%d", &n, &m), o = 0;
  for (int i = 1; i <= n; i++)
    head[i] = vis[i] = deg[i] = f[i] = dep[i] = fa[i] = 0;
  for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), add_edge(u, v);
  bool falg = false;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      Vc = Ec = t = 0, dfs(i, 0);
      if (Vc <= Ec) {
        for (int j = 1; j <= t; j++) f[st[j]] = 1;
        falg = true;
        break;
      }
      int pos = 0;
      for (int j = 1; j <= t; j++)
        if (deg[st[j]] >= 4) {
          pos = j;
          break;
        }
      if (pos) {
        for (int j = 1; j <= t; j++) f[st[j]] = 1;
        f[st[pos]] = 2;
        falg = true;
        break;
      }
      vec.resize(0);
      for (int j = 1; j <= t; j++)
        if (deg[st[j]] == 3) vec.push_back(st[j]);
      if (vec.size() >= 2) {
        int u = vec[0], v = vec[1];
        for (int j = head[u]; j; j = e[j].link) f[e[j].to] = 1;
        for (int j = head[v]; j; j = e[j].link) f[e[j].to] = 1;
        work(u, 0, v);
        falg = true;
        break;
      }
      if (vec.size() == 1) {
        lf.resize(0);
        dfs2(vec[0], 0);
        sort(lf.begin(), lf.end());
        if (lf[0].first >= 3) {
          for (int j = 1; j <= t; j++)
            if (dep[st[j]] >= 2 && dep[st[j]] <= 3) f[st[j]]++, f[fa[st[j]]]++;
          falg = true;
          break;
        }
        if (lf[1].first >= 4) {
          f[vec[0]] = 4;
          for (int j = 1; j <= t; j++) {
            if (dep[st[j]] == 2) f[st[j]] += 2;
            if (dep[st[j]] >= 3 && dep[st[j]] <= 4) f[st[j]]++, f[fa[st[j]]]++;
          }
          falg = true;
          break;
        }
        if (lf[1].first == 3 && lf[2].first >= 6) {
          for (int j = 1; j <= t; j++)
            if (dep[st[j]] <= 6) f[st[j]] = 7 - dep[st[j]];
          f[lf[0].second] = 3;
          f[lf[1].second] = 2, f[fa[lf[1].second]] = 4;
          falg = true;
          break;
        }
      }
    }
  if (!falg) return puts("NO"), void();
  puts("YES");
  for (int i = 1; i <= n; i++) printf("%d ", f[i]);
  puts("");
}
int main() {
  scanf("%d", &T);
  while (T--) solve();
}
