#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int fa[maxn];
int n, m, P, Q;
long long W[maxn];
vector<int> C[maxn];
int find(int x) { return fa[x] < 0 ? x : fa[x] = find(fa[x]); }
inline bool check() {
  int r1 = 0;
  for (int(i) = (int)(1); (i) <= (int)(n); ++(i))
    if (find(i) == i) ++r1;
  if (r1 != Q) return false;
  return true;
}
int main(int argc, char const *argv[]) {
  cin >> n >> m >> P >> Q;
  for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) fa[i] = -1;
  for (int(ll) = 0; (ll) < (int)(m); ++(ll)) {
    int u, v, w;
    cin >> u >> v >> w;
    u = find(u), v = find(v);
    if (u == v)
      W[u] += w;
    else
      fa[u] += fa[v], fa[v] = u, W[u] += W[v] + w;
  }
  int r1 = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  for (int(i) = (int)(1); (i) <= (int)(n); ++(i))
    if (find(i) == i) {
      ++r1;
      q.push(make_pair((W[i]), (i)));
    }
  int p1 = r1 - Q;
  if (p1 < 0) {
    cout << "NO\n";
    return 0;
  }
  long long rc = 0;
  vector<pair<int, int> > res;
  for (int(kk) = 0; (kk) < (int)(min(p1, P)); ++(kk)) {
    if ((int)(q).size() < 2) {
      cout << "NO\n";
      return 0;
    }
    pair<long long, int> v1 = q.top();
    q.pop();
    pair<long long, int> v2 = q.top();
    q.pop();
    rc += min((long long)1e9, v1.first + v2.first + 1);
    res.push_back(pair<int, int>(v1.second, v2.second));
    q.push(make_pair((v1.first + v2.first + 1 + v1.first + v2.first),
                     (v1.second)));
    int u = v1.second, v = v2.second;
    fa[u] += fa[v], fa[v] = u, W[u] += W[v];
  }
  int p2 = P - p1;
  for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) C[find(i)].push_back(i);
  int u1 = -1, u2 = -1;
  for (int(i) = (int)(1); (i) <= (int)(n); ++(i))
    if ((int)(C[i]).size() >= 2) u1 = C[i][0], u2 = C[i][1];
  for (int(kk) = 0; (kk) < (int)(p2); ++(kk)) {
    if (u1 == -1) {
      cout << "NO\n";
      return 0;
    }
    res.push_back(pair<int, int>(u1, u2));
    rc += 1000;
  }
  if (!check()) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  for (int(i) = 0; (i) < (int)((int)(res).size()); ++(i))
    cout << res[i].first << " " << res[i].second << "\n";
  return 0;
}
