#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long INF = 1e9;
int n, m, p, q;
int component[N], color;
pair<long long, int> region[N];
bool vis[N];
struct edge {
  int v;
  long long l;
  edge(int _v, long long _l) {
    v = _v;
    l = _l;
  }
};
vector<edge> nb[N];
priority_queue<pair<long long, int> > pq;
void DFS_Color(int v) {
  vis[v] = true;
  component[v] = color;
  int i;
  for (i = 0; i < nb[v].size(); i++) {
    region[color].first += nb[v][i].l;
    if (!vis[nb[v][i].v]) DFS_Color(nb[v][i].v);
  }
}
bool check() {
  int i;
  for (i = 1; i <= color; i++)
    if (region[i].first > 0) return true;
  return false;
}
int main() {
  int i, j;
  int x, y;
  long long l;
  int bland_u, bland_v;
  long long sum = 0;
  pair<long long, int> a, b, c;
  cin >> n >> m >> p >> q;
  for (i = 1; i <= m; i++) {
    scanf("%d%d%I64d", &x, &y, &l);
    nb[x].push_back(edge(y, l));
    nb[y].push_back(edge(x, l));
    bland_u = x;
    bland_v = y;
  }
  for (i = 1; i <= n; i++) {
    if (!vis[i]) {
      color++;
      region[color].second = i;
      DFS_Color(i);
      region[color].first /= 2;
      region[color].first = min(INF, region[color].first);
    }
  }
  if (color < q || color - p > q) {
    printf("NO\n");
    return 0;
  }
  if (color == q && p > 0 && !check()) {
    printf("NO\n");
    return 0;
  }
  for (i = 1; i <= color; i++)
    pq.push(make_pair(-region[i].first, region[i].second));
  printf("YES\n");
  while (pq.size() > q) {
    a = pq.top();
    pq.pop();
    b = pq.top();
    pq.pop();
    c.first = max(-INF, a.first + b.first - 1 + a.first + b.first);
    c.second = a.second;
    sum -= c.first;
    bland_u = a.second;
    bland_v = b.second;
    printf("%d %d\n", a.second, b.second);
    pq.push(c);
  }
  p -= color - q;
  while (p--) {
    printf("%d %d\n", bland_u, bland_v);
    sum += 1000;
  }
  return 0;
}
