#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
int par[100005];
long long sz[100005];
vector<vector<int> > v;
int get(int x) { return par[x] == x ? x : par[x] = get(par[x]); }
pair<int, int> fix() {
  for (int i = 0; i < v.size(); i++)
    if (v[i].size()) return make_pair(i, v[i][0]);
  return make_pair(-1, -1);
}
int main() {
  int n, m, p, q;
  scanf("%d%d%d%d", &n, &m, &p, &q);
  int pc = p;
  v.resize(n);
  for (int i = 0; i < n; i++) par[i] = i;
  for (int i = 0; i < m; i++) {
    int x, y, l;
    scanf("%d%d%d", &x, &y, &l);
    x--;
    y--;
    if (get(x) == get(y)) {
      sz[get(x)] += l;
      continue;
    }
    sz[get(x)] += sz[get(y)] + l;
    par[get(y)] = get(x);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int temp = 0;
  set<pair<long long, int> > st;
  for (int i = 0; i < n; i++) {
    if (par[i] == i) {
      temp++;
      st.insert(make_pair(sz[i], i));
    }
  }
  if (temp < q) return puts("NO"), 0;
  if (!p) return printf("%s\n", temp == q ? "YES" : "NO"), 0;
  vector<pair<int, int> > ans;
  while (st.size() > q) {
    int a = st.begin()->second;
    st.erase(st.begin());
    int b = st.begin()->second;
    st.erase(st.begin());
    ans.push_back(make_pair(a, b));
    sz[get(a)] +=
        sz[get(b)] + min((long long)1000000000, sz[get(a)] + sz[get(b)] + 1);
    par[get(b)] = get(a);
    v[a].push_back(b);
    v[b].push_back(a);
    st.insert(make_pair(sz[get(a)], get(a)));
    p--;
  }
  if (p) {
    pair<int, int> x = fix();
    for (int i = 0; i < p; i++) ans.push_back(make_pair(x.first, x.second));
    if (ans.back() == make_pair(-1, -1)) return puts("NO"), 0;
  }
  if (st.size() < q || st.size() > q || ans.size() != pc) return puts("NO"), 0;
  puts("YES");
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
}
