#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
int n, m, p, q, cnt, par[N], size[N];
long long sum[N];
bool used[N];
int get(int u) { return u == par[u] ? u : par[u] = get(par[u]); }
void unite(int u, int v, long long w, bool f = false) {
  int p = get(u);
  int q = get(v);
  if (p == q) {
    sum[p] += w;
    return;
  }
  if (size[p] > size[q]) swap(p, q);
  if (!f) --cnt;
  size[q] += size[p];
  par[p] = q;
  sum[q] += sum[p] + w;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &p, &q);
  for (int i = 1; i <= n; ++i) {
    par[i] = i;
    size[i] = 1;
    sum[i] = 0;
  }
  cnt = n;
  while (m--) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    unite(u, v, w);
  }
  if (q > cnt || p < cnt - q) {
    puts("NO");
    return 0;
  }
  if (cnt == n && q == n && p) {
    puts("NO");
    return 0;
  }
  puts("YES");
  set<pair<long long, int> > S;
  int uu = 1;
  for (int i = 1; i <= n; ++i) {
    int u = get(i);
    if (size[u] > 1) uu = u;
    S.insert(make_pair(sum[u], u));
  }
  for (int i = 0; i < cnt - q; ++i) {
    long long s1 = S.begin()->first;
    int pp = S.begin()->second;
    S.erase(S.begin());
    long long s2 = S.begin()->first;
    int qq = S.begin()->second;
    S.erase(S.begin());
    long long s = min(1000000000LL, s1 + s2 + 1);
    unite(pp, qq, s, true);
    printf("%d %d\n", pp, qq);
    pp = get(pp);
    S.insert(make_pair(sum[pp], pp));
  }
  uu = get(uu);
  vector<int> mas;
  for (int i = 1; i <= n && (int)(mas).size() < 2; ++i)
    if (get(i) == uu) mas.push_back(i);
  for (int i = cnt - q; i < p; ++i) printf("%d %d\n", mas[0], mas[1]);
  return 0;
}
