#include <bits/stdc++.h>
using namespace std;
const int max_n = 100111, inf = 1e9 + 100;
int n, m, p, q;
vector<pair<int, int> > v[max_n];
bool vis[max_n];
int col[max_n];
int cnt_com = 0;
vector<int> com_v[max_n];
long long com_s[max_n];
void dfs(int cur) {
  vis[cur] = 1;
  col[cur] = cnt_com;
  for (int i = 0; i < v[cur].size(); ++i) {
    int to = v[cur][i].first;
    if (!vis[to]) {
      dfs(to);
    }
  }
}
int main() {
  cin >> n >> m >> p >> q;
  if (n == 1) {
    if (p > 0) {
      cout << "NO" << endl;
      return 0;
    } else {
      cout << "YES" << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    int from, to, w;
    scanf("%d%d%d", &from, &to, &w);
    --from, --to;
    v[from].push_back(make_pair(to, w));
    v[to].push_back(make_pair(from, w));
  }
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      dfs(i);
      ++cnt_com;
    }
  }
  if (cnt_com < q) {
    cout << "NO" << endl;
    return 0;
  }
  int big_road = cnt_com - q;
  if (big_road > p) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    int from = i;
    com_v[col[i]].push_back(i);
    for (int j = 0; j < v[i].size(); ++j) {
      int to = v[i][j].first;
      long long w = v[i][j].second;
      if (col[from] != col[to]) {
        exit(228);
      }
      if (to > from) {
        com_s[col[from]] += w;
      }
    }
  }
  set<pair<long long, int> > cs;
  for (int i = 0; i < cnt_com; ++i) {
    cs.insert(make_pair(com_s[i], i));
  }
  vector<pair<int, int> > ans;
  for (int i = 0; i < big_road; ++i) {
    pair<long long, int> c1 = *cs.begin();
    cs.erase(cs.begin());
    pair<long long, int> c2 = *cs.begin();
    cs.erase(cs.begin());
    ans.push_back(make_pair(com_v[c1.second][0], com_v[c2.second][0]));
    long long newe = min(1000000000LL, c1.first + c2.first + 1);
    cs.insert(make_pair(c1.first + c2.first + newe, c1.second));
  }
  int lft = p - big_road;
  if (lft) {
    int from = -1, to = -1;
    for (int i = 0; i < n; ++i) {
      if (!v[i].empty()) {
        from = i;
        to = v[i][0].first;
        break;
      }
    }
    if (!ans.empty()) {
      from = ans.back().first;
      to = ans.back().second;
    }
    if (from == -1) {
      cout << "NO" << endl;
      return 0;
    }
    for (int i = 0; i < lft; ++i) {
      ans.push_back(make_pair(from, to));
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
  return 0;
}
