#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
void build() {}
int n, m;
vector<int> v[101010];
void init() {
  n = getint();
  m = getint();
  for (int i = 1; i <= n; i++) v[i].clear();
  while (m--) {
    int ui = getint();
    int vi = getint();
    v[ui].push_back(vi);
    v[vi].push_back(ui);
  }
}
long long ans[101010];
bool vst[101010], tag;
vector<int> vv;
void go(int now, int prt) {
  vst[now] = true;
  vv.push_back(now);
  for (auto i : v[now]) {
    if (i == prt) continue;
    if (not vst[i])
      go(i, now);
    else
      tag = true;
  }
}
void yes() {
  puts("YES");
  for (int i = 1; i <= n; i++) printf("%lld%c", ans[i], " \n"[i == n]);
}
bool ok;
int stk[101010];
void gogo(int now, int dep) {
  vst[now] = true;
  vv.push_back(now);
  stk[dep] = now;
  if (dep and (int) v[now].size() > 2) {
    for (int i : v[stk[0]]) ans[i] = 1;
    for (int i : v[now]) ans[i] = 1;
    for (int i = 0; i <= dep; i++) ans[stk[i]] = 2;
    ok = true;
    yes();
    return;
  }
  for (auto i : v[now]) {
    if (vst[i]) continue;
    gogo(i, dep + 1);
    if (ok) return;
  }
}
long long bal;
long long MX = 6 * 5 * 4 * 3 * 2 * 1;
long long gogo2(int now, int prt, int dep) {
  bool leaf = true;
  long long ret = 0;
  ans[now] = 0;
  if (dep < 5) {
    for (auto son : v[now]) {
      if (son == prt) continue;
      ret = gogo2(son, now, dep + 1);
      ans[now] = max((long long)ans[now], ans[son] + ret);
      leaf = false;
    }
    for (auto son : v[now]) {
      if (son == prt) continue;
      bal += ans[now] * ans[son];
    }
  }
  if (leaf) {
    long long per = MX / (dep + 1);
    ans[now] = per;
    bal -= ans[now] * ans[now];
    return per;
  }
  bal -= ans[now] * ans[now];
  return ret;
}
void solve() {
  for (int i = 1; i <= n; i++) {
    ans[i] = 0;
    vst[i] = false;
  }
  for (int i = 1; i <= n; i++) {
    if (vst[i]) continue;
    vv.clear();
    tag = false;
    go(i, i);
    if (tag) {
      for (auto j : vv) ans[j] = 1;
      yes();
      return;
    }
  }
  for (int i = 1; i <= n; i++)
    if ((int)v[i].size() > 3) {
      ans[i] = 2;
      for (auto j : v[i]) ans[j] = 1;
      yes();
      return;
    }
  for (int i = 1; i <= n; i++) vst[i] = false;
  ok = false;
  for (int i = 1; i <= n; i++) {
    if (vst[i]) continue;
    if ((int)v[i].size() > 2) {
      vv.clear();
      gogo(i, 0);
      if (ok) return;
      bal = 0;
      gogo2(i, i, 0);
      if (bal >= 0) {
        yes();
        return;
      }
      for (auto j : vv) ans[j] = 0;
    }
  }
  puts("NO");
}
int main() {
  build();
  __ = getint();
  while (__--) {
    init();
    solve();
  }
}
