#include <bits/stdc++.h>
using namespace std;
long long n, pq, q, p[100100], sz[100100], we[100100], m;
vector<pair<long long, long long> > g[100200], ed, ans;
bool vis[100100];
set<pair<long long, long long> > w;
long long findp(long long u) {
  if (u == p[u]) return u;
  return p[u] = findp(p[u]);
}
void dfs(long long u, long long pa) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    while (g[u][i].second != pa && pq) {
      ans.push_back({u, g[u][i].second});
      pq--;
    }
    if (!vis[g[u][i].second]) dfs(g[u][i].second, u);
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m >> pq >> q;
  for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;
  for (int i = 0; i < m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    g[x].push_back({z, y});
    g[y].push_back({z, x});
    ed.push_back({x, z});
    x = findp(x);
    y = findp(y);
    if (x != y) {
      if (sz[x] > sz[y]) swap(x, y);
      p[x] = y;
      sz[y] += sz[x];
    }
  }
  for (int i = 0; i < m; i++) {
    long long x, y;
    x = ed[i].first;
    y = ed[i].second;
    x = findp(x);
    we[x] += y;
  }
  for (int i = 1; i <= n; i++) {
    long long x = findp(i);
    w.insert({we[x], x});
  }
  if (w.size() < q) return cout << "NO\n", 0;
  while (pq && w.size() > q) {
    pair<long long, long long> fir, sec;
    fir = *(w.begin());
    w.erase(w.begin());
    sec = *(w.begin());
    w.erase(w.begin());
    long long x = fir.second;
    long long y = sec.second;
    x = findp(x);
    y = findp(y);
    long long wei = 1000;
    if (x != y) {
      if (sz[x] > sz[y]) swap(x, y);
      p[x] = y;
      sz[y] += sz[x];
      wei = min(we[x] + we[y] + 1, (long long)1e9);
      we[y] += we[x];
      we[y] += wei;
      w.insert({we[y], y});
    }
    ans.push_back({x, y});
    g[x].push_back({wei, y});
    g[y].push_back({wei, x});
    pq--;
  }
  if (pq == 0 && w.size() > q) return cout << "NO\n", 0;
  for (int i = 1; i <= n; i++) {
    dfs(findp(i), 0);
  }
  if (pq > 0) return cout << "NO\n", 0;
  cout << "YES\n";
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
  return 0;
}
