#include <bits/stdc++.h>
using namespace std;
int n, m, p, q, p1, p2, x, y, d, f[101000];
long long s[101000];
struct cmp {
  bool operator()(int &a, int &b) { return s[a] > s[b]; }
};
int find(int t) {
  if (f[t] != t) f[t] = find(f[t]);
  return f[t];
}
void init() {
  scanf("%d%d%d%d", &n, &m, &p, &q);
  q = n - q;
  for (int i = (1); i <= (n); ++i) f[i] = i;
  for (int i = (1); i <= (m); ++i) {
    scanf("%d%d%d", &x, &y, &d);
    p1 = find(x);
    p2 = find(y);
    if (p1 != p2) {
      q--;
      s[p1] += s[p2] + d;
      f[p2] = p1;
    } else
      s[p1] += d;
  }
}
void work() {
  if (q < 0 || q > p || !q && !m && p) {
    puts("NO");
    return;
  }
  puts("YES");
  priority_queue<int, vector<int>, cmp> Q;
  for (int i = (1); i <= (n); ++i)
    if (find(i) == i) Q.push(i);
  while (q--) {
    x = find(Q.top());
    Q.pop();
    y = find(Q.top());
    Q.pop();
    printf("%d %d\n", x, y);
    s[x] += s[y];
    s[x] += (1e9 > s[x] + 1 ? s[x] + 1 : 1e9);
    f[y] = x;
    Q.push(x);
    p--;
  }
  for (int i = (1); i <= (n); ++i)
    if (find(i) != i) {
      for (int j = (1); j <= (p); ++j) printf("%d %d\n", find(i), i);
      break;
    }
}
int main() {
  init();
  work();
  return 0;
}
