3 5
2 1 608591421 720962564
3 2 608591421 641991574
3 2 718110706 353409763
2 3 482786015 858341723
3 2 825397574 357507279
 2 1
2 1 317425595 636156322
 50000 1
20845 28516 904146168 997637433

Yes
641991574 1
2 
 Yes
0 0

 Yes
0 0


#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
int addnum, vel[800010], ne[800010], head[800010];
int dfn[200010], low[200010], vis[200010], q[200010], co[200010];
int tim, col, top;
int n, m;
vector<int> o[50010];
int x[50010], y[50010], c[50010], t[50010];
inline int read() {
  int ans = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  return ans;
}
void add(int u, int v) {
  addnum++, vel[addnum] = v, ne[addnum] = head[u], head[u] = addnum;
}
void tarjan(int u, int fa) {
  dfn[u] = low[u] = ++tim;
  vis[u] = 1;
  q[++top] = u;
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    if (!vis[v]) {
      tarjan(v, u);
      low[u] = min(low[u], low[v]);
    } else if (vis[v] == 1)
      low[u] = min(low[u], dfn[v]);
  }
  vis[u] = 2;
  if (dfn[u] == low[u]) {
    col++;
    while (q[top] != u) co[q[top--]] = col;
    co[q[top--]] = col;
  }
}
int check(int num) {
  addnum = 0;
  col = 0;
  tim = 0;
  for (int i = 1; i <= m * 4; i++) head[i] = vis[i] = co[i] = 0;
  for (int i = 1; i <= n; i++) {
    int siz = o[i].size();
    for (int j = 0; j < siz; j++) {
      int u = o[i][j];
      if (t[u] > num) add(u, u + m);
      if (j) add(u, o[i][j - 1] + m + m), add(u + m + m, o[i][j - 1] + m + m);
      if (j + 1 < siz)
        add(u, o[i][j + 1] + m + m + m),
            add(u + m + m + m, o[i][j + 1] + m + m + m);
      add(u + m + m, u + m), add(u + m + m + m, u + m);
    }
    for (int j = 1; j < siz; j++) {
      if (c[o[i][j]] == c[o[i][j - 1]]) {
        if (j + 1 < siz && c[o[i][j]] == c[o[i][j + 1]]) return 0;
        add(o[i][j] + m, o[i][j - 1]);
        add(o[i][j - 1] + m, o[i][j]);
      }
    }
  }
  for (int i = 1; i <= m * 4; i++)
    if (!vis[i]) tarjan(i, -1);
  for (int i = 1; i <= m; i++)
    if (co[i] == co[i + m]) return 0;
  return 1;
}
inline int cmp(int x, int y) { return c[x] < c[y]; }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    x[i] = read(), y[i] = read(), c[i] = read(), t[i] = read();
    o[x[i]].push_back(i);
    o[y[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) sort(o[i].begin(), o[i].end(), cmp);
  int l = 0, r = inf;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (r == inf) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  check(r);
  for (int i = 1; i <= m; i++)
    if (co[i] < co[i + m]) printf("%d %d\n", x[i], y[i]);
}
