#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const long long int MAX_N = 100010;
long long int n, m, p, q;
vector<pair<long long int, long long int> > G[MAX_N];
long long int cmp[MAX_N];
long long int re[MAX_N];
long long int sum[MAX_N];
long long int ca, cb;
set<pair<long long int, long long int> > ss;
vector<pair<long long int, long long int> > ans;
void dfs(long long int x, long long int k) {
  cmp[x] = k;
  for (auto &w : G[x]) {
    ca = x, cb = w.first;
    sum[k] += w.second;
    if (cmp[w.first] == -1) dfs(w.first, k);
  }
}
int main() {
  scanf("%lld %lld %lld %lld", &n, &m, &p, &q);
  for (long long int i = (0); i < (long long int)(m); i++) {
    long long int a, b, l;
    scanf("%lld %lld %lld", &a, &b, &l);
    a--;
    b--;
    G[a].emplace_back(b, l);
    G[b].emplace_back(a, l);
  }
  long long int k = 0;
  for (long long int i = (0); i < (long long int)(n); i++) cmp[i] = -1;
  for (long long int i = (0); i < (long long int)(n); i++)
    if (cmp[i] == -1) {
      re[k] = i;
      dfs(i, k);
      sum[k] /= 2;
      ss.insert(pair<long long int, long long int>(sum[k], k));
      k++;
    }
  long long int nk = k - q;
  long long int od = p - nk;
  if (nk < 0 || od < 0 || (q == n && p > 0)) {
    puts("NO");
    return 0;
  }
  for (long long int i = (0); i < (long long int)(nk); i++) {
    pair<long long int, long long int> a = *ss.begin();
    ss.erase(ss.begin());
    pair<long long int, long long int> b = *ss.begin();
    ss.erase(ss.begin());
    ans.emplace_back(re[a.second], re[b.second]);
    ca = re[a.second], cb = re[b.second];
    ss.insert(pair<long long int, long long int>(
        a.first + b.first + min(a.first + b.first + 1, (long long int)1e9),
        a.second));
  }
  for (long long int i = (0); i < (long long int)(od); i++)
    ans.emplace_back(ca, cb);
  printf("YES\n");
  for (auto &w : ans) printf("%lld %lld\n", w.first + 1, w.second + 1);
  return 0;
}
