#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)((t).size()))); ++(i)) s << t[i] << " ";
  return s;
}
int tab[100007];
int find(int a) { return tab[a] == a ? a : tab[a] = find(tab[a]); }
void unia(int a, int b) {
  a = find(a), b = find(b);
  tab[a] = b;
}
long long len[100007];
vector<int> sz[100007];
int main() {
  int(n), (m);
  scanf("%d %d", &(n), &(m));
  int(p), (q);
  scanf("%d %d", &(p), &(q));
  vector<pair<pair<int, int>, int> > v;
  for (int(i) = 1; (i) <= (n); ++(i)) tab[i] = i;
  for (int(i) = 0; (i) < (m); ++(i)) {
    int(x), (y), (l);
    scanf("%d %d %d", &(x), &(y), &(l));
    v.push_back(make_pair(make_pair(x, y), l));
    unia(x, y);
  }
  for (typeof(v.begin()) it = v.begin(); it != v.end(); it++) {
    len[find(it->first.first)] += it->second;
  }
  int k = 0;
  for (int(i) = 1; (i) <= (n); ++(i))
    if (i == find(i)) ++k;
  if (k < q || k - p > q || (k == n && q == n && p > 0)) {
    printf("NO");
    return 0;
  }
  printf("YES\n");
  pair<int, int> podwojny;
  for (int(i) = 1; (i) <= (n); ++(i)) sz[find(i)].push_back(i);
  for (int(i) = 1; (i) <= (n); ++(i))
    if (((int)((sz[i]).size())) >= 2) podwojny = make_pair(sz[i][0], sz[i][1]);
  set<pair<long long, int> > st;
  for (int(i) = 1; (i) <= (n); ++(i))
    if (i == find(i)) st.insert(make_pair(len[i], i));
  for (int(u) = 0; (u) < (k - q); ++(u)) {
    set<pair<long long, int> >::iterator it, jt;
    it = st.begin();
    jt = it;
    ++jt;
    printf("%d %d\n", it->second, jt->second);
    int repr = it->second;
    long long nowy =
        it->first + jt->first + min(1000000000LL, 1 + it->first + jt->first);
    podwojny = make_pair(it->second, jt->second);
    st.erase(it);
    st.erase(jt);
    st.insert(make_pair(nowy, repr));
  }
  for (int(u) = 0; (u) < (p - (k - q)); ++(u)) {
    printf("%d %d\n", podwojny.first, podwojny.second);
  }
}
