#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const long long oo = 1e9;
int n, m, q, p;
vector<pair<long long, int> > head[maxN];
bool mark[maxN];
int com, v1, v2;
long long sum;
set<pair<long long, int> > s;
void DFS(int u) {
  mark[u] = true;
  for (int i = 0; i < (int)head[u].size(); ++i) {
    int second = head[u][i].second;
    sum += (long long)head[u][i].first;
    if (!mark[second]) DFS(second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d%d%d", &n, &m, &p, &q);
  int x, y, c;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &c);
    v1 = x;
    v2 = y;
    head[x].push_back(pair<long long, int>((long long)c, y));
    head[y].push_back(pair<long long, int>((long long)c, x));
  }
  memset(mark, false, sizeof mark);
  for (int i = 1; i <= n; ++i)
    if (!mark[i]) {
      ++com;
      sum = 0;
      DFS(i);
      sum /= 2;
      s.insert(pair<long long, int>(sum, i));
    }
  if (q > com || p < (com - q) || (q == n && p != 0))
    printf("NO\n");
  else {
    printf("YES\n");
    while (q < com) {
      --p;
      --com;
      set<pair<long long, int> >::iterator it;
      it = s.begin();
      long long sum = it->first;
      int u = it->second;
      s.erase(s.begin());
      it = s.begin();
      sum += it->first;
      int second = it->second;
      s.erase(s.begin());
      printf("%d %d\n", u, second);
      v1 = u;
      v2 = second;
      s.insert(pair<long long, int>(min(oo, sum + 1) + sum, u));
    }
    while (p--) printf("%d %d\n", v1, v2);
  }
  return 0;
}
