#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int P = 1e9 + 7;
const double PI = 3.14159265358979;
const long long lINF = 1e18;
const double eps = 1e-7;
vector<vector<pair<int, long long> > > graph(100001);
vector<char> used(100001, false);
vector<long long> sum(100001, 0);
void dfs(int v) {
  used[v] = true;
  for (int i = 0; i < (int)graph[v].size(); ++i) {
    if (!used[graph[v][i].first]) {
      sum[v] += graph[v][i].second;
      dfs(graph[v][i].first);
      sum[v] += sum[graph[v][i].first];
    } else
      sum[v] += graph[v][i].second;
  }
}
int main() {
  pair<int, int> et = make_pair(-1, -1);
  int n, m, p, q;
  cin >> n >> m >> p >> q;
  if (n == 1) {
    if (p == 0 && q == 1) {
      cout << "YES";
      return 0;
    } else {
      cout << "NO";
      return 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (et.first == -1) et = make_pair(a, b);
    graph[a - 1].push_back(make_pair(b - 1, c));
    graph[b - 1].push_back(make_pair(a - 1, c));
  }
  int comp = 0;
  set<pair<long long, int> > vc;
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      dfs(i);
      ++comp;
      vc.insert(make_pair(min(sum[i] / 2, (long long)INF), i));
    }
  }
  if (p == 0) {
    if (comp == q) {
      cout << "YES";
      return 0;
    } else {
      cout << "NO";
      return 0;
    }
  }
  if (comp - q > p || (et.first == -1 && comp == q) || q > comp) {
    cout << "NO";
    return 0;
  } else
    cout << "YES\n";
  int i = 0;
  for (; i < p && i < comp - q; ++i) {
    pair<long long, int> now = *(vc.begin());
    vc.erase(vc.begin());
    if (et.first == -1) et = make_pair(now.second + 1, vc.begin()->second + 1);
    cout << now.second + 1 << ' ' << vc.begin()->second + 1 << endl;
    now.first = min(2 * now.first + 2 * vc.begin()->first + 1, (long long)INF);
    vc.erase(vc.begin());
    vc.insert(now);
  }
  for (; i < p; ++i) {
    cout << et.first << ' ' << et.second << endl;
  }
  return 0;
}
