#include <bits/stdc++.h>
using namespace std;
set<pair<long long, int> > s;
vector<pair<long long, int> > v;
int father[100010];
long long value[100010];
int parent(int a) {
  return (father[a] == a ? a : father[a] = parent(father[a]));
}
void join(int a, int b) {
  a = parent(a);
  b = parent(b);
  if (a == b) return;
  value[a] += value[b];
  father[b] = a;
}
int main() {
  int n, m, p, q;
  cin >> n >> m >> p >> q;
  for (int i = 1; i <= n; i++) {
    father[i] = i;
    value[i] = 0;
  }
  int e1 = -1, e2 = -1;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    e1 = a, e2 = b;
    join(a, b);
    value[parent(a)] += c;
  }
  for (int i = 1; i <= n; i++)
    s.insert(pair<long long, int>(value[parent(i)], parent(i)));
  bool merge = m > 0;
  while (s.size() > q && p > 0) {
    pair<long long, int> a = *s.begin();
    s.erase(s.begin());
    pair<long long, int> b = *s.begin();
    s.erase(s.begin());
    int weight = min(1000000000ll,
                     value[parent(a.second)] + value[parent(b.second)] + 1);
    v.push_back(pair<long long, int>(parent(a.second), parent(b.second)));
    join(a.second, b.second);
    value[parent(a.second)] += weight;
    s.insert(pair<long long, int>(value[parent(a.second)], parent(a.second)));
    p--;
    merge = true;
  }
  if ((p == 0 || (p > 0 && merge)) && s.size() == q) {
    cout << "YES" << endl;
    for (int i = 0; i < v.size(); i++)
      cout << v[i].first << " " << v[i].second << endl;
    if (v.size() > 0)
      for (int i = 0; i < p; i++)
        cout << v[0].first << " " << v[0].second << endl;
    else
      for (int i = 0; i < p; i++) cout << e1 << " " << e2 << endl;
  } else
    cout << "NO" << endl;
}
