#include <bits/stdc++.h>
using namespace std;
int n, m, p, q, i, comp, x, y, z;
long long s[100001], viz[100001], from[100001], vertex[100001];
vector<int> g[100001];
vector<pair<int, long long> > heap;
void dfs(int v) {
  viz[v] = comp;
  s[comp] += from[v];
  for (int j = 0; j < g[v].size(); j++)
    if (viz[g[v][j]] == 0) dfs(g[v][j]);
};
bool how(pair<int, long long> A, pair<int, long long> B) {
  return A.second > B.second;
};
void add_in_heap(pair<int, long long> v) {
  heap.push_back(v);
  push_heap(heap.begin(), heap.end(), how);
};
void del_in_heap() {
  pop_heap(heap.begin(), heap.end(), how);
  heap.pop_back();
};
vector<int> ans1, ans2;
int main() {
  cin >> n >> m >> p >> q;
  for (i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    from[x] += z;
    from[y] += z;
    g[x].push_back(y);
    g[y].push_back(x);
  };
  make_heap(heap.begin(), heap.end());
  for (i = 1; i <= n; i++)
    if (viz[i] == 0) {
      comp++;
      vertex[comp] = i;
      dfs(i);
      s[comp] /= 2;
      add_in_heap(make_pair(comp, s[comp]));
    };
  if (comp < q || (m == 0 && comp == q && p > 0) || comp > p + q) {
    cout << "NO";
    return 0;
  };
  while (comp > q) {
    p--;
    comp--;
    pair<int, int> l = heap.front();
    del_in_heap();
    pair<int, int> r = heap.front();
    del_in_heap();
    ans1.push_back(vertex[l.first]);
    ans2.push_back(vertex[r.first]);
    g[vertex[l.first]].push_back(vertex[r.first]);
    g[vertex[r.first]].push_back(vertex[l.first]);
    pair<int, int> u;
    u.first = l.first;
    u.second = min(1000000000, l.second + r.second + 1) + l.second + r.second;
    add_in_heap(u);
  };
  for (i = 1; i <= n; i++)
    if (g[i].size() > 0) break;
  while (p > 0 && i <= n) {
    p--;
    ans1.push_back(i);
    ans2.push_back(g[i][0]);
  }
  if (p == 0) {
    cout << "YES" << endl;
    for (i = 0; i < ans1.size(); i++) cout << ans1[i] << " " << ans2[i] << endl;
  } else
    cout << "NO";
  return 0;
}
