#include <bits/stdc++.h>
using namespace std;
int n, m, p, q;
int fa[111111];
long long s[111111];
const long long UB = 1000000000LL;
int getfa(int id) { return fa[id] == id ? id : fa[id] = getfa(fa[id]); }
void solve() {
  while (~scanf("%d%d%d%d", &n, &m, &p, &q)) {
    int i, j;
    for (i = 1; i <= n; i++) fa[i] = i;
    set<int> S;
    set<pair<long long, int> > M;
    set<pair<long long, int> >::iterator iter;
    long long tmd = 0;
    pair<int, int> tp = make_pair(-1, -1);
    for (i = 1; i <= n; i++) S.insert(i);
    for (i = 1; i <= n; i++) M.insert(make_pair(0, i));
    for (j = 1; j <= m; j++) {
      int x, y, l;
      scanf("%d%d%d", &x, &y, &l);
      tmd += l;
      int fx = getfa(x);
      int fy = getfa(y);
      if (fx != fy) {
        fa[fx] = fy;
        M.erase(M.find(make_pair(s[fx], fx)));
        M.erase(M.find(make_pair(s[fy], fy)));
        s[fy] += s[fx] + l;
        s[fx] = 0;
        M.insert(make_pair(s[fy], fy));
        tp = make_pair(x, y);
        S.erase(S.find(fx));
      } else {
        M.erase(M.find(make_pair(s[fx], fx)));
        s[fx] += l;
        tp = make_pair(x, y);
        M.insert(make_pair(s[fx], fx));
      }
    }
    if (n == 1) {
      if (p == 0 && q == 1)
        printf("YES\n");
      else
        printf("NO\n");
      continue;
    }
    if (S.size() < q) {
      printf("NO\n");
      continue;
    }
    vector<pair<int, int> > res;
    for (i = 1; i <= p; i++) {
      if (S.size() == q) {
        if (tp.first == -1)
          break;
        else {
          res.push_back(tp);
          int fx = getfa(tp.first);
          M.erase(M.find(make_pair(s[fx], fx)));
          tmd += 1000;
          s[fx] += 1000;
          M.insert(make_pair(s[fx], fx));
        }
      } else {
        iter = M.begin();
        pair<long long, int> x = *iter;
        M.erase(iter);
        iter = M.begin();
        pair<long long, int> y = *iter;
        M.erase(iter);
        fa[x.second] = fa[y.second];
        long long how = min(UB, s[x.second] + s[y.second] + 1);
        s[y.second] += s[x.second] + how;
        s[x.second] = 0;
        tmd += how;
        M.insert(make_pair(s[y.second], y.second));
        tp = make_pair(x.second, y.second);
        res.push_back(tp);
        S.erase(S.find(x.second));
      }
    }
    if (S.size() == q && res.size() == p) {
      printf("YES\n");
      for (i = 0; i < res.size(); i++)
        printf("%d %d\n", res[i].first, res[i].second);
    } else
      printf("NO\n");
  }
}
int main() {
  solve();
  return 0;
}
