#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
int fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x, y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){

        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    for (int i = 1; i < num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1, 1000000000)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        if (fai == i) continue;
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < Q){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != Q){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
int fa[maxn], sum[maxn], asd[maxn];
int find(int x){
	if (fa[x] == x) return x;
	return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
	int x, y;
	bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
	scanf("%d%d%d%d", &n, &m, &P, &Q);
	for (int i = 1; i <= n; i ++) fa[i] = i;
	for (int i = 1; i <= m; i ++){
		int a = 0, b = 0, c = 0;
		scanf("%d%d%d", &a, &b, &c);
		int fax = find(a), fay = find(b);
		fa[fay] = fax; sum[a] += c, sum[b] += c;
	}
	for (int i = 1; i <= n; i ++){
		int fai = find(i);
		asd[fai] += sum[i];
		if (fai == i){
			num ++;
			aa[num] = i;
		}
	}
//	cout <<num <<endl;
	for (int i = 1; i <= num; i ++){
//		cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
		head.push((Tzy){aa[i], asd[aa[i]] / 2});
	}

}
int ans[maxn][2];
void work(){
	int ans1 = 0;
	for (int i = 1; i <= num - Q; i ++){
		Tzy a = head.top(); head.pop();
		Tzy b = head.top(); head.pop();
		ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
		head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1, 1000000000)});
		fa[b.x] = fa[a.x];
	}
	if (ans1 > P){
		puts("NO");
		return;
	}
//	puts("YES");
	for (int i = 1; i <= n; i ++){
		int fai = find(i);
		if (fai == i) continue;
		for (int j = i + 1; j <= n; j ++){
			int faj = find(j);
			if (fai == faj)
				while (ans1 < Q){
					ans[++ ans1][0] = i;
					ans[ans1][1] = j;
				}
		}
	}
	if (ans1 != Q){ puts("NO"); return;}
	puts("YES");
	for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
	init();
	work();
	return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
int fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x, y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1, 1000000000)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        if (fai == i) continue;
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < P){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != P){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
typedef long long LL;
LL fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x; LL  y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    if (num < Q){
        puts("NO");
        return;
    }
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1LL, 1000000000LL)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj){
                while (ans1 < P){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
                if (ans1 == P) break;
        }
    }
    if (ans1 != P){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
int fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x, y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    if (num < Q){
        puts("NO");
        return;
    }
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1, 1000000000)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        if (fai == i) continue;
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < P){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != P){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
typedef long long LL;
LL fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x; LL  y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    if (num < Q){
        puts("NO");
        return;
    }
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1LL, 1000000000LL)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        if (fai == i) continue;
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < P){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != P){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
int fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x, y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    for (int i = 1; i < num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1, 1000000000)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        if (fai == i) continue;
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < Q){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != Q){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
typedef long long LL;
LL fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x; LL  y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    if (num < Q){
        puts("NO");
        return;
    }
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1LL, 1000000000LL)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < P){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != P){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
int fa[maxn], sum[maxn], asd[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x, y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
//  cout <<num <<endl;
    for (int i = 1; i <= num; i ++){
//      cout <<aa[i] <<' ' <<asd[aa[i]] / 2 <<endl;
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1, 1000000000)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        if (fai == i) continue;
        for (int j = i + 1; j <= n; j ++){
            int faj = find(j);
            if (fai == faj)
                while (ans1 < Q){
                    ans[++ ans1][0] = i;
                    ans[ans1][1] = j;
                }
        }
    }
    if (ans1 != Q){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = 510000;
typedef long long LL;
LL fa[maxn], sum[maxn], asd[maxn], ss[maxn];
int find(int x){
    if (fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
int aa[maxn];
struct Tzy{
    int x; LL  y;
    bool  operator < (const Tzy b) const { return y > b.y; }
};
priority_queue<Tzy>head;
int num, n, m, Q, P;
void init(){
    scanf("%d%d%d%d", &n, &m, &P, &Q);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++){
        int a = 0, b = 0, c = 0;
        scanf("%d%d%d", &a, &b, &c);
        int fax = find(a), fay = find(b);
        fa[fay] = fax; sum[a] += c, sum[b] += c;
    }
    for (int i = 1; i <= n; i ++){
        int fai = find(i);
        asd[fai] += sum[i];
        if (fai == i){
            num ++;
            aa[num] = i;
        }
    }
    for (int i = 1; i <= num; i ++){
        head.push((Tzy){aa[i], asd[aa[i]] / 2});
    }

}
int ans[maxn][2];
void work(){
    int ans1 = 0;
    if (num < Q){
        puts("NO");
        return;
    }
    for (int i = 1; i <= num - Q; i ++){
        Tzy a = head.top(); head.pop();
        Tzy b = head.top(); head.pop();
        ans[++ ans1][0] = a.x, ans[ans1][1] = b.x;
        head.push((Tzy){a.x, a.y + b.y + min(a.y + b.y + 1LL, 1000000000LL)});
        fa[b.x] = fa[a.x];
    }
    if (ans1 > P){
        puts("NO");
        return;
    }
//  puts("YES");    for (int i = 1; i <= n;  ++){

    for (int j = 1; j <= n; j ++){
        int faj = find(j);
        if (j == faj)
            while (ans1 < P){
                ans[++ ans1][0] = faj;
                ans[ans1][1] = j;
            }

        if (ans1 == P) break;
    }
    if (ans1 != P){ puts("NO"); return;}
    puts("YES");
    for (int i = 1; i <= ans1; i ++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
int main(){
    init();
    work();
    return 0;
}
/*
6 1 2 5
3 4 1000
*/


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
typedef long long int uli;
using namespace std;

typedef pair<uli,int> par;
const int mx = 1e5+5;
vector<pair<int,uli> >g[mx];
bool vis[mx];
uli total;

void dfs(int u){
    vis[u] = true;
    for(int i=0;i<g[u].size();i++){
        total+=g[u][i].second;
        if(!vis[g[u][i].first]){
            dfs(g[u][i].first);
        }
    }
}

int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,u,v,i,j,k;
    int lu,lv;
    lu = lv = -1;
    uli w;
    cin>>n>>m>>p>>q;
    for(i=0;i<m;i++){
        cin>>u>>v>>w;
        lu = u, lv = v;
        g[u].push_back(make_pair(v,w));
        g[v].push_back(make_pair(u,w));
    }
    fill(vis,vis+mx,0);
    priority_queue<par,vector<par>,greater<par> > pq;
    int ng = 0;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            total/=2;
            pq.push(make_pair(total,i));
            ng++;
        }
    }
    par a,b;
    uli mv = 1e9;
    if(ng-p<=q && ng>=q){
        if(p-(ng-q)>0 && pq.size()<=q){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            while(pq.size()>q){
                a = pq.top();
                pq.pop();
                b = pq.top();
                pq.pop();

                uli e = min(mv,a.first+b.first+1);
                uli v = a.first+b.first+e;
                pq.push(make_pair(v,a.second));
                cout<<a.second<<" "<<b.second<<endl;
                lu = a.second, lv = b.second;
            }
            for(i=0;i<p-(ng-q);i++){
                cout<<lu<<" "<<lv<<endl;
            }
        }
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
typedef long long int uli;
using namespace std;

typedef pair<uli,int> par;
const int mx = 1e5+5;
vector<pair<int,uli> >g[mx];
bool vis[mx];
uli total;

void dfs(int u){
    vis[u] = true;
    for(int i=0;i<g[u].size();i++){
        total+=g[u][i].second;
        if(!vis[g[u][i].first]){
            dfs(g[u][i].first);
        }
    }
}

int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,u,v,i,j,k;
    int lu,lv;
    lu = lv = -1;
    uli w;
    cin>>n>>m>>p>>q;
    for(i=0;i<m;i++){
        cin>>u>>v>>w;
        lu = u, lv = v;
        g[u].push_back(make_pair(v,w));
        g[v].push_back(make_pair(u,w));
    }
    fill(vis,vis+mx,0);
    priority_queue<par,vector<par>,greater<par> > pq;
    int ng = 0;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            total/=2;
            pq.push(make_pair(total,i));
            ng++;
        }
    }
    par a,b;
    uli mv = 1e9;
    if(ng-p<=q && ng>=q){
        if(p-(ng-q)>0 && lu==-1){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            while(pq.size()>q){
                a = pq.top();
                pq.pop();
                b = pq.top();
                pq.pop();

                uli e = min(mv,a.first+b.first+1);
                uli v = a.first+b.first+e;
                pq.push(make_pair(v,a.second));
                cout<<a.second<<" "<<b.second<<endl;
            }
            for(i=0;i<p-(ng-q);i++){
                cout<<lu<<" "<<lv<<endl;
            }
        }
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
typedef long long int uli;
using namespace std;

typedef pair<uli,int> par;
const int mx = 1e5+5;
vector<pair<int,uli> >g[mx];
bool vis[mx];
uli total;

void dfs(int u){
    vis[u] = true;
    for(int i=0;i<g[u].size();i++){
        total+=g[u][i].second;
        if(!vis[g[u][i].first]){
            dfs(g[u][i].first);
        }
    }
}

int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,u,v,i,j,k;
    int lu,lv;
    lu = lv = -1;
    uli w;
    cin>>n>>m>>p>>q;
    for(i=0;i<m;i++){
        cin>>u>>v>>w;
        lu = u, lv = v;
        g[u].push_back(make_pair(v,w));
        g[v].push_back(make_pair(u,w));
    }
    fill(vis,vis+mx,0);
    priority_queue<par,vector<par>,greater<par> > pq;
    int ng = 0;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            total/=2;
            pq.push(make_pair(total,i));
            ng++;
        }
    }
    par a,b;
    uli mv = 1e9;
    if(ng-p<=q){
        if(p-(ng-q)>0 && lu==-1){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
            while(pq.size()>q){
                a = pq.top();
                pq.pop();
                b = pq.top();
                pq.pop();

                uli e = min(mv,a.first+b.first+1);
                uli v = a.first+b.first+e;
                pq.push(make_pair(v,a.second));
                cout<<a.second<<" "<<b.second<<endl;
            }
            for(i=0;i<p-(ng-q);i++){
                cout<<lu<<" "<<lv<<endl;
            }
        }
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long int uli;
typedef pair<uli,int> par;
#define mp make_pair
#define fs first
#define sc second

const int mx = 1e5+5;
const uli maxi = 1e9;
map<int,int> g[mx];
uli groups[mx];
bool vis[mx];
uli total = 0;

void dfs(int u){
    vis[u] = true;
    map<int,int>::iterator it;
    map<int,int>ch = g[u];
    for(it=ch.begin();it!=ch.end();it++){
        if(!vis[it->fs]){
            total+=it->sc;
            dfs(it->fs);
        }
    }
}
int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,i,j,k,u,v,l,fu,fv;
    cin>>n>>m>>p>>q;
    for(i=0;i<m;i++){
        cin>>u>>v>>l;
        fu = u;
        fv = v;
        if(g[u].count(v)==0)
            g[u][v] = l;
        else
            g[u][v] += l;

        if(g[v].count(u)==0)
            g[v][u] = l;
        else
            g[v][u] += l;
    }
    fill(vis,vis+mx,0);
    int ng = 0;
    priority_queue<par,vector<par>,greater<par> >pq;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            pq.push(mp(total,i));
            ng++;
        }
    }
    par a,b;
    if(ng-p<=q && ng>=q){
        while(pq.size()>q){
            a = pq.top();
            pq.pop();
            b = pq.top();
            pq.pop();

            uli e = min(a.fs+b.fs+1,maxi);
            uli v = a.fs+b.fs+e;
            pq.push(mp(e,a.sc) );

            cout<<a.sc<<" "<<b.sc<<endl;
        }
        for(i=0;i<p-(ng-q);i++){
            cout<<fu<<" "<<fv<<endl;
        }
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long int uli;
typedef pair<uli,int> par;
#define mp make_pair
#define fs first
#define sc second

const int mx = 1e5+5;
const uli maxi = 1e9;
map<int,int> g[mx];
uli groups[mx];
bool vis[mx];
uli total = 0;

void dfs(int u){
    vis[u] = true;
    map<int,int>::iterator it;
    map<int,int>ch = g[u];
    for(it=ch.begin();it!=ch.end();it++){
        if(!vis[it->fs]){
            dfs(it->fs);
        }
        total+=it->sc;
    }
}
int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,i,j,k,u,v,l,fu,fv;
    cin>>n>>m>>p>>q;
    fu = fv = -1;
    for(i=0;i<m;i++){
        cin>>u>>v>>l;
        fu = u;
        fv = v;
        if(g[u].count(v)==0)
            g[u][v] = l;
        else
            g[u][v] += l;

        if(g[v].count(u)==0)
            g[v][u] = l;
        else
            g[v][u] += l;
    }
    fill(vis,vis+mx,0);
    int ng = 0;
    priority_queue<par,vector<par>,greater<par> >pq;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            total/=2;
 //           cout<<"root="<<i<<" total="<<total<<endl;
            pq.push(mp(total,i));
            ng++;
        }
    }
    par a,b;
    if(ng-p<=q && ng>=q){
        if(p-(ng-q)>0 && fu==-1){
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<"YES"<<endl;
        while(pq.size()>q){
            a = pq.top();
            pq.pop();
            b = pq.top();
            pq.pop();

            uli e = min(a.fs+b.fs+1,maxi);
            uli v = a.fs+b.fs+e;
            pq.push(mp(e,a.sc) );

            cout<<a.sc<<" "<<b.sc<<endl;
        }
        for(i=0;i<p-(ng-q);i++){
            cout<<fu<<" "<<fv<<endl;
        }
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long int uli;
typedef pair<uli,int> par;
#define mp make_pair
#define fs first
#define sc second

const int mx = 1e5+5;
const uli maxi = 1e9;
map<int,int> g[mx];
uli groups[mx];
bool vis[mx];
uli total = 0;

void dfs(int u){
    vis[u] = true;
    map<int,int>::iterator it;
    map<int,int>ch = g[u];
    for(it=ch.begin();it!=ch.end();it++){
        if(!vis[it->fs]){
            dfs(it->fs);
        }
        total+=it->sc;
    }
}
int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,i,j,k,u,v,l,fu,fv;
    cin>>n>>m>>p>>q;
    fu = fv = -1;
    for(i=0;i<m;i++){
        cin>>u>>v>>l;
        fu = u;
        fv = v;
        if(g[u].count(v)==0)
            g[u][v] = l;
        else
            g[u][v] += l;

        if(g[v].count(u)==0)
            g[v][u] = l;
        else
            g[v][u] += l;
    }
    fill(vis,vis+mx,0);
    int ng = 0;
    priority_queue<par,vector<par>,greater<par> >pq;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            total/=2;
 //           cout<<"root="<<i<<" total="<<total<<endl;
            pq.push(mp(total,i));
            ng++;
        }
    }
    par a,b;
    if(ng-p<=q && ng>=q){
        if(p-(ng-q)>0 && fu==-1){
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<"YES"<<endl;
        while(pq.size()>q){
            a = pq.top();
            pq.pop();
            b = pq.top();
            pq.pop();

            uli e = min(a.fs+b.fs+1,maxi);
            uli v = a.fs+b.fs+e;
            pq.push(mp(v,a.sc) );

            cout<<a.sc<<" "<<b.sc<<endl;
        }
        for(i=0;i<p-(ng-q);i++){
            cout<<fu<<" "<<fv<<endl;
        }
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long int uli;
typedef pair<uli,int> par;
#define mp make_pair
#define fs first
#define sc second

const int mx = 1e5+5;
const uli maxi = 1e9;
map<int,int> g[mx];
uli groups[mx];
bool vis[mx];
uli total = 0;

void dfs(int u){
    vis[u] = true;
    map<int,int>::iterator it;
    map<int,int>ch = g[u];
    for(it=ch.begin();it!=ch.end();it++){
        if(!vis[it->fs]){
            total+=it->sc;
            dfs(it->fs);
        }
    }
}
int main(){
//  freopen("data.in","r",stdin);
    int n,m,p,q,i,j,k,u,v,l,fu,fv;
    cin>>n>>m>>p>>q;
    fu = fv = -1;
    for(i=0;i<m;i++){
        cin>>u>>v>>l;
        fu = u;
        fv = v;
        if(g[u].count(v)==0)
            g[u][v] = l;
        else
            g[u][v] += l;

        if(g[v].count(u)==0)
            g[v][u] = l;
        else
            g[v][u] += l;
    }
    fill(vis,vis+mx,0);
    int ng = 0;
    priority_queue<par,vector<par>,greater<par> >pq;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            pq.push(mp(total,i));
            ng++;
        }
    }
    par a,b;
    if(ng-p<=q && ng>=q){
        if(p-(ng-q)>0 && fu==-1){
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<"YES"<<endl;
        while(pq.size()>q){
            a = pq.top();
            pq.pop();
            b = pq.top();
            pq.pop();

            uli e = min(a.fs+b.fs+1,maxi);
            uli v = a.fs+b.fs+e;
            pq.push(mp(e,a.sc) );

            cout<<a.sc<<" "<<b.sc<<endl;
        }
        for(i=0;i<p-(ng-q);i++){
            cout<<fu<<" "<<fv<<endl;
        }
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<utility>
#include<list>
#include<vector>
#include<queue>
typedef long long int uli;
using namespace std;

typedef pair<uli,int> par;
const int mx = 1e5+5;
vector<pair<int,uli> >g[mx];
bool vis[mx];
uli total;

vector<int>xs,ys;
void dfs(int u){
    vis[u] = true;
    for(int i=0;i<g[u].size();i++){
        total+=g[u][i].second;
        if(!vis[g[u][i].first]){
            dfs(g[u][i].first);
        }
    }
}

int main(){
//    freopen("data.in","r",stdin);
    int n,m,p,q,u,v,i,j,k;
    int lu,lv;
    lu = lv = -1;
    uli w;
    cin>>n>>m>>p>>q;
    for(i=0;i<m;i++){
        cin>>u>>v>>w;
        lu = u, lv = v;
        g[u].push_back(make_pair(v,w));
        g[v].push_back(make_pair(u,w));
    }
    fill(vis,vis+mx,0);
    priority_queue<par,vector<par>,greater<par> > pq;
    int ng = 0;
    for(i=1;i<=n;i++){
        if(!vis[i]){
            total = 0;
            dfs(i);
            total/=2;
            pq.push(make_pair(total,i));
            ng++;
        }
    }
    par a,b;
    uli mv = 1e9;
    if(ng-p<=q && ng>=q){
        while(pq.size()>q){
            a = pq.top();
            pq.pop();
            b = pq.top();
            pq.pop();

            uli e = min(mv,a.first+b.first+1);
            uli v = a.first+b.first+e;
            pq.push(make_pair(v,a.second));
            xs.push_back(a.second);
            ys.push_back(b.second);
//            cout<<a.second<<" "<<b.second<<endl;
            lu = a.second, lv = b.second;
        }
        bool ok = true;
        if(p-(ng-q)>0){
            if(lu==-1){
                ok = false;
            }
            else{
                for(i=0;i<p-(ng-q);i++){
                    xs.push_back(lu);
                    ys.push_back(lv);
                }
            }
        }
        if(ok){
            cout<<"YES"<<endl;
            for(i=0;i<xs.size();i++)
                cout<<xs[i]<<" "<<ys[i]<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5,MX=1e9;
int n,p,q,x,y,tot_edge,head[N],tot_cmp,sum_cmp[N],id_cmp[N],cnt[N];
bool vis[N];
struct Edge{
	int to,nxt,cost;
}edge[N<<1];
struct UNIT{
	int amt,id;
	inline bool operator <(const UNIT &tmp)const{
		return amt>tmp.amt;
	}
};
priority_queue<UNIT>pque;
void rd(int &res){
	res=0;
	char c;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
		while(c=getchar(),c>47);
}
inline void add_edge(int from,int to,int len){
	edge[tot_edge]=(Edge){to,head[from],len};
	head[from]=tot_edge++;
}
void dfs(int cur){
	vis[cur]=true;
	if(++cnt[tot_cmp]==2){
		x=cur;
		y=id_cmp[tot_cmp];
	}
	for(int i=head[cur];~i;i=edge[i].nxt){
		int to=edge[i].to;
		if(vis[to])continue;
		sum_cmp[tot_cmp]+=edge[i].cost;
		if(sum_cmp[tot_cmp]>=MX)sum_cmp[tot_cmp]=MX;
		dfs(to);
	}
}
void solve(){
	int need=tot_cmp-q;
	if(q>tot_cmp||need>p||!need&&p&&x==-1){
		puts("NO");
		return;
	}
	puts("YES");
	while(!pque.empty())pque.pop();
	for(int i=0;i<tot_cmp;++i)
		pque.push((UNIT){sum_cmp[i],id_cmp[i]});
	while(need--){
		UNIT a=pque.top();
		pque.pop();
		UNIT b=pque.top();
		pque.pop();
		printf("%d %d\n",a.id,b.id);
		if(x==-1){
			x=a.id;
			y=b.id;
		}
		int cost=min(a.amt+b.amt+1,MX);
		cost+=a.amt;
		if(cost>=MX)cost=MX;
		cost+=b.amt;
		if(cost>=MX)cost=MX;
		pque.push((UNIT){cost,a.id});
		--p;
	}
	while(p--)printf("%d %d\n",x,y);
}
int main(){
	int m,u,v,len;
	rd(n);rd(m);rd(p);rd(q);
	tot_edge=0;
	memset(head,-1,n+1<<2);
	while(m--){
		rd(u);rd(v);rd(len);
		add_edge(u,v,len);
		add_edge(v,u,len);
	}
	tot_cmp=0;
	memset(vis,false,n+1);
	x=-1;
	for(int i=1;i<=n;++i){
		if(vis[i])continue;
		sum_cmp[tot_cmp]=cnt[tot_cmp]=0;
		id_cmp[tot_cmp]=i;
		dfs(i);
		++tot_cmp;
	}
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,p,q,x,y,tot_edge,head[N],id[N],tot_cmp,id_cmp[N],cnt[N];
bool vis[N];
typedef __int64 ll;
const ll MX=1e9;
ll sum_cmp[N];
struct Edge{
	int to,nxt,cost;
}edge[N<<1];
struct UNIT{
	ll amt;
	int id;
	inline bool operator <(const UNIT &tmp)const{
		return amt>tmp.amt;
	}
};
priority_queue<UNIT>pque;
void rd(int &res){
	res=0;
	char c;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
		while(c=getchar(),c>47);
}
inline void add_edge(int from,int to,int len){
	edge[tot_edge]=(Edge){to,head[from],len};
	head[from]=tot_edge++;
}
void dfs(int cur){
	vis[cur]=true;
	id[cur]=tot_cmp;
	if(++cnt[tot_cmp]==2){
		x=cur;
		y=id_cmp[tot_cmp];
	}
	for(int i=head[cur];~i;i=edge[i].nxt){
		int to=edge[i].to;
		if(!vis[to])id[to]=id[cur];
		if(id[to]==id[cur])sum_cmp[tot_cmp]+=edge[i].cost;
		if(vis[to])continue;
		dfs(to);
	}
}
void solve(){
	int need=tot_cmp-q;
	if(q>tot_cmp||need>p||!need&&p&&x==-1){
		puts("NO");
		return;
	}
	puts("YES");
	while(!pque.empty())pque.pop();
	for(int i=0;i<tot_cmp;++i)
		pque.push((UNIT){sum_cmp[i],id_cmp[i]});
	while(need--){
		UNIT a=pque.top();
		pque.pop();
		UNIT b=pque.top();
		pque.pop();
		printf("%d %d\n",a.id,b.id);
		if(x==-1){
			x=a.id;
			y=b.id;
		}
		ll cost=min(a.amt+b.amt+1,MX);
		pque.push((UNIT){a.amt+b.amt+cost,a.id});
		--p;
	}
	while(p--)printf("%d %d\n",x,y);
}
int main(){
	int m,u,v,len;
	rd(n);rd(m);rd(p);rd(q);
	tot_edge=0;
	memset(head,-1,n+1<<2);
	memset(id,-1,n+1<<2);
	while(m--){
		rd(u);rd(v);rd(len);
		add_edge(u,v,len);
		add_edge(v,u,len);
	}
	tot_cmp=0;
	memset(vis,false,n+1);
	x=-1;
	for(int i=1;i<=n;++i){
		if(vis[i])continue;
		sum_cmp[tot_cmp]=cnt[tot_cmp]=0;
		id_cmp[tot_cmp]=i;
		dfs(i);
		++tot_cmp;
	}
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,p,q,x,y,tot_edge,head[N],tot_cmp,id_cmp[N],cnt[N];
bool vis[N];
typedef __int64 ll;
const ll MX=1e9;
ll sum_cmp[N];
struct Edge{
	int to,nxt,cost;
}edge[N<<1];
struct UNIT{
	ll amt;
	int id;
	inline bool operator <(const UNIT &tmp)const{
		return amt>tmp.amt;
	}
};
priority_queue<UNIT>pque;
void rd(int &res){
	res=0;
	char c;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
		while(c=getchar(),c>47);
}
inline void add_edge(int from,int to,int len){
	edge[tot_edge]=(Edge){to,head[from],len};
	head[from]=tot_edge++;
}
void dfs(int cur){
	vis[cur]=true;
	if(++cnt[tot_cmp]==2){
		x=cur;
		y=id_cmp[tot_cmp];
	}
	for(int i=head[cur];~i;i=edge[i].nxt){
		int to=edge[i].to;
		if(vis[to])continue;
		sum_cmp[tot_cmp]+=edge[i].cost;
		dfs(to);
	}
}
void solve(){
	int need=tot_cmp-q;
	if(q>tot_cmp||need>p||!need&&p&&x==-1){
		puts("NO");
		return;
	}
	puts("YES");
	while(!pque.empty())pque.pop();
	for(int i=0;i<tot_cmp;++i)
		pque.push((UNIT){sum_cmp[i],id_cmp[i]});
	while(need--){
		UNIT a=pque.top();
		pque.pop();
		UNIT b=pque.top();
		pque.pop();
		printf("%d %d\n",a.id,b.id);
		if(x==-1){
			x=a.id;
			y=b.id;
		}
		ll cost=min(a.amt+b.amt+1,MX);
		pque.push((UNIT){a.amt+b.amt+cost,a.id});
		--p;
	}
	while(p--)printf("%d %d\n",x,y);
}
int main(){
	int size = 256 << 20; // 256MB
	char *p = (char*)malloc(size) + size;
	__asm__("movl %0, %%esp\n" :: "r"(p));
	int m,u,v,len;
	rd(n);rd(m);rd(p);rd(q);
	tot_edge=0;
	memset(head,-1,n+1<<2);
	while(m--){
		rd(u);rd(v);rd(len);
		add_edge(u,v,len);
		add_edge(v,u,len);
	}
	tot_cmp=0;
	memset(vis,false,n+1);
	x=-1;
	for(int i=1;i<=n;++i){
		if(vis[i])continue;
		sum_cmp[tot_cmp]=cnt[tot_cmp]=0;
		id_cmp[tot_cmp]=i;
		dfs(i);
		++tot_cmp;
	}
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5,MX=1e9;
int n,p,q,x,y,tot_edge,head[N],tot_cmp,sum_cmp[N],id_cmp[N],cnt[N];
bool vis[N];
struct Edge{
	int to,nxt,cost;
}edge[N<<1];
struct UNIT{
	int amt,id;
	inline bool operator <(const UNIT &tmp)const{
		return amt>tmp.amt;
	}
};
priority_queue<UNIT>pque;
void rd(int &res){
	res=0;
	char c;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
		while(c=getchar(),c>47);
}
inline void add_edge(int from,int to,int len){
	edge[tot_edge]=(Edge){to,head[from],len};
	head[from]=tot_edge++;
}
void dfs(int cur){
	vis[cur]=true;
	if(++cnt[tot_cmp]==2){
		x=cur;
		y=id_cmp[tot_cmp];
	}
	for(int i=head[cur];~i;i=edge[i].nxt){
		int to=edge[i].to;
		if(vis[to])continue;
		sum_cmp[tot_cmp]+=edge[i].cost;
		if(sum_cmp[tot_cmp]>=MX)sum_cmp[tot_cmp]=MX;
		dfs(to);
	}
}
void solve(){
	int need=tot_cmp-q;
	if(q>tot_cmp||need>p||need<p&&x==-1){
		puts("NO");
		return;
	}
	puts("YES");
	while(!pque.empty())pque.pop();
	for(int i=0;i<tot_cmp;++i)
		pque.push((UNIT){sum_cmp[i],id_cmp[i]});
	while(need--){
		UNIT a=pque.top();
		pque.pop();
		UNIT b=pque.top();
		pque.pop();
		printf("%d %d\n",a.id,b.id);
		int cost=min(a.amt+b.amt+1,MX);
		cost+=a.amt;
		if(cost>=MX)cost=MX;
		cost+=b.amt;
		if(cost>=MX)cost=MX;
		pque.push((UNIT){cost,a.id});
		--p;
	}
	while(p--)printf("%d %d\n",x,y);
}
int main(){
	int m,u,v,len;
	rd(n);rd(m);rd(p);rd(q);
	tot_edge=0;
	memset(head,-1,n+1<<2);
	while(m--){
		rd(u);rd(v);rd(len);
		add_edge(u,v,len);
		add_edge(v,u,len);
	}
	tot_cmp=0;
	memset(vis,false,n+1);
	x=-1;
	for(int i=1;i<=n;++i){
		if(vis[i])continue;
		sum_cmp[tot_cmp]=cnt[tot_cmp]=0;
		id_cmp[tot_cmp]=i;
		dfs(i);
		++tot_cmp;
	}
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,p,q,x,y,tot_edge,head[N],tot_cmp,id_cmp[N],cnt[N];
bool vis[N];
typedef __int64 ll;
const ll MX=1e9;
ll sum_cmp[N];
struct Edge{
	int to,nxt,cost;
}edge[N<<1];
struct UNIT{
	ll amt;
	int id;
	inline bool operator <(const UNIT &tmp)const{
		return amt>tmp.amt;
	}
};
priority_queue<UNIT>pque;
void rd(int &res){
	res=0;
	char c;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
		while(c=getchar(),c>47);
}
inline void add_edge(int from,int to,int len){
	edge[tot_edge]=(Edge){to,head[from],len};
	head[from]=tot_edge++;
}
void dfs(int cur){
	vis[cur]=true;
	if(++cnt[tot_cmp]==2){
		x=cur;
		y=id_cmp[tot_cmp];
	}
	for(int i=head[cur];~i;i=edge[i].nxt){
		int to=edge[i].to;
		if(vis[to])continue;
		sum_cmp[tot_cmp]+=edge[i].cost;
		dfs(to);
	}
}
void solve(){
	int need=tot_cmp-q;
	if(q>tot_cmp||need>p||!need&&p&&x==-1){
		puts("NO");
		return;
	}
	puts("YES");
	while(!pque.empty())pque.pop();
	for(int i=0;i<tot_cmp;++i)
		pque.push((UNIT){sum_cmp[i],id_cmp[i]});
	while(need--){
		UNIT a=pque.top();
		pque.pop();
		UNIT b=pque.top();
		pque.pop();
		printf("%d %d\n",a.id,b.id);
		if(x==-1){
			x=a.id;
			y=b.id;
		}
		ll cost=min(a.amt+b.amt+1,MX);
		pque.push((UNIT){a.amt+b.amt+cost,a.id});
		--p;
	}
	while(p--)printf("%d %d\n",x,y);
}
int main(){
	int m,u,v,len;
	rd(n);rd(m);rd(p);rd(q);
	tot_edge=0;
	memset(head,-1,n+1<<2);
	while(m--){
		rd(u);rd(v);rd(len);
		add_edge(u,v,len);
		add_edge(v,u,len);
	}
	tot_cmp=0;
	memset(vis,false,n+1);
	x=-1;
	for(int i=1;i<=n;++i){
		if(vis[i])continue;
		sum_cmp[tot_cmp]=cnt[tot_cmp]=0;
		id_cmp[tot_cmp]=i;
		dfs(i);
		++tot_cmp;
	}
	solve();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int n,p,q,x,y,tot_edge,head[N],id[N],tot_cmp,id_cmp[N],cnt[N];
bool vis[N];
typedef __int64 ll;
const ll MX=1e9;
ll sum_cmp[N];
struct EDGE{
	int u,v,cost;
}es[N];
struct Edge{
	int to,nxt,cost;
}edge[N<<1];
struct UNIT{
	ll amt;
	int id;
	inline bool operator <(const UNIT &tmp)const{
		return amt>tmp.amt;
	}
};
priority_queue<UNIT>pque;
void rd(int &res){
	res=0;
	char c;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
		while(c=getchar(),c>47);
}
inline void add_edge(int from,int to,int len){
	edge[tot_edge]=(Edge){to,head[from],len};
	head[from]=tot_edge++;
}
void dfs(int cur){
	vis[cur]=true;
	id[cur]=tot_cmp;
	if(++cnt[tot_cmp]==2){
		x=cur;
		y=id_cmp[tot_cmp];
	}
	for(int i=head[cur];~i;i=edge[i].nxt){
		int to=edge[i].to;
		if(vis[to])continue;
		dfs(to);
	}
}
void solve(){
	int need=tot_cmp-q;
	if(q>tot_cmp||need>p||!need&&p&&x==-1){
		puts("NO");
		return;
	}
	puts("YES");
	while(!pque.empty())pque.pop();
	for(int i=0;i<tot_cmp;++i)
		pque.push((UNIT){sum_cmp[i],id_cmp[i]});
	while(need--){
		UNIT a=pque.top();
		pque.pop();
		UNIT b=pque.top();
		pque.pop();
		printf("%d %d\n",a.id,b.id);
		if(x==-1){
			x=a.id;
			y=b.id;
		}
		ll cost=min(a.amt+b.amt+1,MX);
		pque.push((UNIT){a.amt+b.amt+cost,a.id});
		--p;
	}
	while(p--)printf("%d %d\n",x,y);
}
int main(){
	int m,u,v,len;
	rd(n);rd(m);rd(p);rd(q);
	tot_edge=0;
	memset(head,-1,n+1<<2);
	memset(id,-1,n+1<<2);
	for(int i=0;i<m;++i){
		rd(u);rd(v);rd(len);
		add_edge(u,v,len);
		add_edge(v,u,len);
		es[i]=(EDGE){u,v,len};
	}
	tot_cmp=0;
	memset(vis,false,n+1);
	x=-1;
	for(int i=1;i<=n;++i){
		if(vis[i])continue;
		sum_cmp[tot_cmp]=cnt[tot_cmp]=0;
		id_cmp[tot_cmp]=i;
		dfs(i);
		++tot_cmp;
	}
	for(int i=0;i<m;++i){
		sum_cmp[id[es[i].u]]+=es[i].cost;
	}
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 1000000000000000
# define A 1000000000
ll l[N],reg[N],x[N],y[N],lg[N];
bool vis[N];
int k;
vector <pair<ll,ll > >g[N];
vector<ll> gn[N];
void dfs(int x,int rg)
{
	reg[x]=rg;
	gn[rg].pb(x);
	vis[x]=true;
	for(int i=0;i<g[x].size();i++)
	{
		if(!vis[g[x][i].ff])
			dfs(g[x][i].ff,rg);
	}
}

ll findregion()
{
   for(int i=(k-1);i>=1;i--)
   	 if(gn[i].size()>=2)
   	 	return i;
    return 0;
}

int main()
{
	IOS;
	int n,m,p,q;
	cin >> n >> m >> p >> q;
	for(int i=0;i<m;i++)
	{
		cin >> x[i] >> y[i] >> l[i];
		g[x[i]].pb(mp(y[i],l[i]));
		g[y[i]].pb(mp(x[i],l[i]));
	}
	 k=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,k++);
		}
	}
	int treg=(k-1);
	if(treg<q)
	{
		cout << "NO";
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		lg[reg[x[i]]]+=l[i];
	}

	priority_queue< ii, vector<ii>, greater<ii> > pq;
	for(ll i=1;i<=treg;i++)
	{
		//trace2(lg[i],i);
		pq.push(mp(lg[i],i));
	}
	int edcnt=0;
	vector<pair<ll,ll> > fans;
	while(!pq.empty() && treg>q)
	{
		ii front1 = pq.top(); pq.pop();
		ii front2;
		if(!pq.empty())
		{
			  front2=pq.top();
			 pq.pop();
		}
		else
		{
			cout << "NO";
			return 0;
		}
		//trace4(front1.ff,front1.ss,front2.ff,front2.ss);
		ll ro1=front1.ss;
		ll ro2=front2.ss;
		//trace2(gn[ro1][0],gn[ro2][0]);
		fans.pb(mp(gn[ro1][0],gn[ro2][0]));
		treg--;
		lg[ro1]+=min((ll)A,front1.ff+front2.ff+1LL);
		lg[ro1]+=lg[ro2];
		pq.push(mp(lg[(ro1)],(ro1)));
		gn[(ro1)].pb(g[ro2][0].ff);
		//g[(k-1)].pb(g[ro2][0]);
		gn[ro2].clear();
		edcnt++;

	}
	if(edcnt<p)
	{
		ll id=findregion();
		if(id==0)
		{
			cout << "NO";
			return 0;
		}
		else
		{
			for(int i=0;i<(p-edcnt);i++)
				fans.pb(mp(g[id][0].ff,g[id][1].ff));
		}
	}

	cout << "YES"<<"\n";
	for(int i=0;i<fans.size();i++)
		cout << fans[i].ff<<" "<< fans[i].ss<<"\n";

}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 1000000000000000
# define A 1000000000
ll l[N],reg[N],x[N],y[N],lg[N];
bool vis[N];
int k;
vector <pair<ll,ll > >g[N];
vector<ll> gn[N];
void dfs(int x,int rg)
{
	reg[x]=rg;
	gn[rg].pb(x);
	vis[x]=true;
	for(int i=0;i<g[x].size();i++)
	{
		if(!vis[g[x][i].ff])
			dfs(g[x][i].ff,rg);
	}
}

ll findregion()
{
   for(int i=(k-1);i>=1;i--)
   	 if(gn[i].size()>=2)
   	 	return i;
    return 0;
}

int main()
{
	IOS;
	int n,m,p,q;
	cin >> n >> m >> p >> q;
	for(int i=0;i<m;i++)
	{
		cin >> x[i] >> y[i] >> l[i];
		g[x[i]].pb(mp(y[i],l[i]));
		g[y[i]].pb(mp(x[i],l[i]));
	}
	 k=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,k++);
		}
	}
	int treg=(k-1);
	if(treg<q)
	{
		cout << "NO";
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		lg[reg[x[i]]]+=l[i];
	}

	priority_queue< ii, vector<ii>, greater<ii> > pq;
	for(ll i=1;i<=treg;i++)
	{
		//trace2(lg[i],i);
		pq.push(mp(lg[i],i));
	}
	int edcnt=0;
	vector<pair<ll,ll> > fans;
	//int edcnt=0;
	while(!pq.empty() && treg>q && edcnt<p)
	{
		ii front1 = pq.top(); pq.pop();
		ii front2;
		if(!pq.empty())
		{
			  front2=pq.top();
			 pq.pop();
		}
		else
		{
			cout << "NO";
			return 0;
		}
		//trace4(front1.ff,front1.ss,front2.ff,front2.ss);
		ll ro1=front1.ss;
		ll ro2=front2.ss;
		//trace2(gn[ro1][0],gn[ro2][0]);
		fans.pb(mp(gn[ro1][0],gn[ro2][0]));
		treg--;
		lg[ro1]+=min((ll)A,front1.ff+front2.ff+1LL);
		lg[ro1]+=lg[ro2];
		pq.push(mp(lg[(ro1)],(ro1)));
		gn[(ro1)].pb(gn[ro2][0]);
		//g[(k-1)].pb(g[ro2][0]);
		gn[ro2].clear();
		edcnt++;

	}
	if(edcnt<p)
	{
		ll id=findregion();
		if(id==0)
		{
			cout << "NO";
			return 0;
		}
		else
		{
			for(int i=0;i<(p-edcnt);i++)
				fans.pb(mp(gn[id][0],gn[id][1]));
		}
	}
	if(edcnt!=p || treg!=q)
	{
		cout << "NO";
		return 0;
	}

	cout << "YES"<<"\n";
	for(int i=0;i<fans.size();i++)
		cout << fans[i].ff<<" "<< fans[i].ss<<"\n";

}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 1000000000000000
# define A 1000000000
ll l[N],reg[N],x[N],y[N],lg[N];
bool vis[N];
int k;
vector <pair<ll,ll > >g[N];
vector<ll> gn[N];
void dfs(int x,int rg)
{
	reg[x]=rg;
	gn[rg].pb(x);
	vis[x]=true;
	for(int i=0;i<g[x].size();i++)
	{
		if(!vis[g[x][i].ff])
			dfs(g[x][i].ff,rg);
	}
}

ll findregion()
{
   for(int i=(k-1);i>=1;i--)
   	 if(gn[i].size()>=2)
   	 	return i;
    return 0;
}
//Hi
int main()
{
	IOS;
	int n,m,p,q;
	cin >> n >> m >> p >> q;
	for(int i=0;i<m;i++)
	{
		cin >> x[i] >> y[i] >> l[i];
		g[x[i]].pb(mp(y[i],l[i]));
		g[y[i]].pb(mp(x[i],l[i]));
	}
	 k=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,k++);
		}
	}
	int treg=(k-1);
	if(treg<q)
	{
		cout << "NO";
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		lg[reg[x[i]]]+=l[i];
	}

	priority_queue< ii, vector<ii>, greater<ii> > pq;
	for(ll i=1;i<=treg;i++)
	{
		//trace2(lg[i],i);
		pq.push(mp(lg[i],i));
	}
	int edcnt=0;
	vector<pair<ll,ll> > fans;
	//int edcnt=0;
	while(!pq.empty() && treg>q && edcnt<p)
	{
		ii front1 = pq.top(); pq.pop();
		ii front2;
		if(!pq.empty())
		{
			  front2=pq.top();
			 pq.pop();
		}
		else
		{
			cout << "NO";
			return 0;
		}
		//trace4(front1.ff,front1.ss,front2.ff,front2.ss);
		ll ro1=front1.ss;
		ll ro2=front2.ss;
		//trace2(gn[ro1][0],gn[ro2][0]);
		fans.pb(mp(gn[ro1][0],gn[ro2][0]));
		treg--;
		lg[ro1]+=min((ll)A,front1.ff+front2.ff+1LL);
		lg[ro1]+=lg[ro2];
		pq.push(mp(lg[(ro1)],(ro1)));
		gn[(ro1)].pb(gn[ro2][0]);
		//g[(k-1)].pb(g[ro2][0]);
		gn[ro2].clear();
		edcnt++;

	}
	//trace2(p,edcnt);
	int t1=edcnt;
	if(edcnt<p)
	{
		ll id=findregion();
		if(id==0)
		{
			cout << "NO";
			return 0;
		}
		else
		{
			for(int i=0;i<(p-t1);i++)
				{
					fans.pb(mp(gn[id][0],gn[id][1]));
					edcnt++;
					//trace1(edcnt);
				}
		}
	}
	//trace2(edcnt,treg);
	if(edcnt!=p || treg!=q)
	{
		cout << "NO";
		return 0;
	}

	cout << "YES"<<"\n";
	for(int i=0;i<fans.size();i++)
		cout << fans[i].ff<<" "<< fans[i].ss<<"\n";

}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 1000000000000000
# define A 1000000000
ll l[N],reg[N],x[N],y[N],lg[N];
bool vis[N];
int k;
vector <pair<ll,ll > >g[N];
vector<ll> gn[N];
void dfs(int x,int rg)
{
	reg[x]=rg;
	gn[rg].pb(x);
	vis[x]=true;
	for(int i=0;i<g[x].size();i++)
	{
		if(!vis[g[x][i].ff])
			dfs(g[x][i].ff,rg);
	}
}

ll findregion()
{
   for(int i=(k-1);i>=1;i--)
   	 if(gn[i].size()>=2)
   	 	return i;
    return 0;
}

int main()
{
	IOS;
	int n,m,p,q;
	cin >> n >> m >> p >> q;
	for(int i=0;i<m;i++)
	{
		cin >> x[i] >> y[i] >> l[i];
		g[x[i]].pb(mp(y[i],l[i]));
		g[y[i]].pb(mp(x[i],l[i]));
	}
	 k=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,k++);
		}
	}
	int treg=(k-1);
	if(treg<q)
	{
		cout << "NO";
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		lg[reg[x[i]]]+=l[i];
	}

	priority_queue< ii, vector<ii>, greater<ii> > pq;
	for(ll i=1;i<=treg;i++)
	{
		//trace2(lg[i],i);
		pq.push(mp(lg[i],i));
	}
	int edcnt=0;
	vector<pair<ll,ll> > fans;
	//int edcnt=0;
	while(!pq.empty() && treg>q && edcnt<p)
	{
		ii front1 = pq.top(); pq.pop();
		ii front2;
		if(!pq.empty())
		{
			  front2=pq.top();
			 pq.pop();
		}
		else
		{
			cout << "NO";
			return 0;
		}
		//trace4(front1.ff,front1.ss,front2.ff,front2.ss);
		ll ro1=front1.ss;
		ll ro2=front2.ss;
		//trace2(gn[ro1][0],gn[ro2][0]);
		fans.pb(mp(gn[ro1][0],gn[ro2][0]));
		treg--;
		lg[ro1]+=min((ll)A,front1.ff+front2.ff+1LL);
		lg[ro1]+=lg[ro2];
		pq.push(mp(lg[(ro1)],(ro1)));
		gn[(ro1)].pb(gn[ro2][0]);
		//g[(k-1)].pb(g[ro2][0]);
		gn[ro2].clear();
		edcnt++;

	}
	//trace2(p,edcnt);
	int t1=edcnt;
	if(edcnt<p)
	{
		ll id=findregion();
		if(id==0)
		{
			cout << "NO";
			return 0;
		}
		else
		{
			for(int i=0;i<(p-t1);i++)
				{
					fans.pb(mp(gn[id][0],gn[id][1]));
					edcnt++;
					//trace1(edcnt);
				}
		}
	}
	//trace2(edcnt,treg);
	if(edcnt!=p || treg!=q)
	{
		cout << "NO";
		return 0;
	}

	cout << "YES"<<"\n";
	for(int i=0;i<fans.size();i++)
		cout << fans[i].ff<<" "<< fans[i].ss<<"\n";

}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 1000000000000000
# define A 1000000000
ll l[N],reg[N],x[N],y[N],lg[N];
bool vis[N];
int k;
vector <pair<ll,ll > >g[N];
vector<ll> gn[N];
void dfs(int x,int rg)
{
	reg[x]=rg;
	gn[rg].pb(x);
	vis[x]=true;
	for(int i=0;i<g[x].size();i++)
	{
		if(!vis[g[x][i].ff])
			dfs(g[x][i].ff,rg);
	}
}

ll findregion()
{
   for(int i=(k-1);i>=1;i--)
   	 if(gn[i].size()>=2)
   	 	return i;
    return 0;
}

int main()
{
	IOS;
	int n,m,p,q;
	cin >> n >> m >> p >> q;
	for(int i=0;i<m;i++)
	{
		cin >> x[i] >> y[i] >> l[i];
		g[x[i]].pb(mp(y[i],l[i]));
		g[y[i]].pb(mp(x[i],l[i]));
	}
	 k=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,k++);
		}
	}
	int treg=(k-1);
	if(treg<q)
	{
		cout << "NO";
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		lg[reg[x[i]]]+=l[i];
	}

	priority_queue< ii, vector<ii>, greater<ii> > pq;
	for(ll i=1;i<=treg;i++)
	{
		//trace2(lg[i],i);
		pq.push(mp(lg[i],i));
	}
	int edcnt=0;
	vector<pair<ll,ll> > fans;
	//int edcnt=0;
	while(!pq.empty() && treg>q && edcnt<p)
	{
		ii front1 = pq.top(); pq.pop();
		ii front2;
		if(!pq.empty())
		{
			  front2=pq.top();
			 pq.pop();
		}
		else
		{
			cout << "NO";
			return 0;
		}
		//trace4(front1.ff,front1.ss,front2.ff,front2.ss);
		ll ro1=front1.ss;
		ll ro2=front2.ss;
		//trace2(gn[ro1][0],gn[ro2][0]);
		fans.pb(mp(gn[ro1][0],gn[ro2][0]));
		treg--;
		lg[ro1]+=min((ll)A,front1.ff+front2.ff+1LL);
		lg[ro1]+=lg[ro2];
		pq.push(mp(lg[(ro1)],(ro1)));
		gn[(ro1)].pb(gn[ro2][0]);
		//g[(k-1)].pb(g[ro2][0]);
		gn[ro2].clear();
		edcnt++;

	}
	if(edcnt<p)
	{
		ll id=findregion();
		if(id==0)
		{
			cout << "NO";
			return 0;
		}
		else
		{
			for(int i=0;i<(p-edcnt);i++)
				{
					fans.pb(mp(gn[id][0],gn[id][1]));
					edcnt++;
				}
		}
	}
	if(edcnt!=p || treg!=q)
	{
		cout << "NO";
		return 0;
	}

	cout << "YES"<<"\n";
	for(int i=0;i<fans.size();i++)
		cout << fans[i].ff<<" "<< fans[i].ss<<"\n";

}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 1000000000000000
# define A 1000000000
ll l[N],reg[N],x[N],y[N],lg[N];
bool vis[N];
int k;
vector <pair<ll,ll > >g[N];
vector<ll> gn[N];
void dfs(int x,int rg)
{
	reg[x]=rg;
	gn[rg].pb(x);
	vis[x]=true;
	for(int i=0;i<g[x].size();i++)
	{
		if(!vis[g[x][i].ff])
			dfs(g[x][i].ff,rg);
	}
}

ll findregion()
{
   for(int i=(k-1);i>=1;i--)
   	 if(gn[i].size()>=2)
   	 	return i;
    return 0;
}

int main()
{
	IOS;
	int n,m,p,q;
	cin >> n >> m >> p >> q;
	for(int i=0;i<m;i++)
	{
		cin >> x[i] >> y[i] >> l[i];
		g[x[i]].pb(mp(y[i],l[i]));
		g[y[i]].pb(mp(x[i],l[i]));
	}
	 k=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,k++);
		}
	}
	int treg=(k-1);
	if(treg<q)
	{
		cout << "NO";
		return 0;
	}
	for(int i=0;i<m;i++)
	{
		lg[reg[x[i]]]+=l[i];
	}

	priority_queue< ii, vector<ii>, greater<ii> > pq;
	for(ll i=1;i<=treg;i++)
	{
		//trace2(lg[i],i);
		pq.push(mp(lg[i],i));
	}
	int edcnt=0;
	vector<pair<ll,ll> > fans;
	while(!pq.empty() && treg>q)
	{
		ii front1 = pq.top(); pq.pop();
		ii front2;
		if(!pq.empty())
		{
			  front2=pq.top();
			 pq.pop();
		}
		else
		{
			cout << "NO";
			return 0;
		}
		//trace4(front1.ff,front1.ss,front2.ff,front2.ss);
		ll ro1=front1.ss;
		ll ro2=front2.ss;
		//trace2(gn[ro1][0],gn[ro2][0]);
		fans.pb(mp(gn[ro1][0],gn[ro2][0]));
		treg--;
		lg[ro1]+=min((ll)A,front1.ff+front2.ff+1LL);
		lg[ro1]+=lg[ro2];
		pq.push(mp(lg[(ro1)],(ro1)));
		gn[(ro1)].pb(gn[ro2][0]);
		//g[(k-1)].pb(g[ro2][0]);
		gn[ro2].clear();
		edcnt++;

	}
	if(edcnt<p)
	{
		ll id=findregion();
		if(id==0)
		{
			cout << "NO";
			return 0;
		}
		else
		{
			for(int i=0;i<(p-edcnt);i++)
				fans.pb(mp(gn[id][0],gn[id][1]));
		}
	}

	cout << "YES"<<"\n";
	for(int i=0;i<fans.size();i++)
		cout << fans[i].ff<<" "<< fans[i].ss<<"\n";

}


#include<bits/stdc++.h>
using namespace std;
void solve(int n,int a[],int m,int b[]){
    int ok=0,ok1=0,x,y;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int sum=a[i]+b[j];
               x=a[i],y=b[j];
               for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(sum!=a[i] && sum!=b[i]){
                        ok=1;
                    }
                }
               }
               if(ok==1){
                    ok1=1;
                break;
               }
}
   if(ok1==1){
    break;
   }
}
cout<<x<<" "<<y<<endl;
}
int main(){
  int n,m;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cin>>m;
  int b[m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  solve(n,a,m,b);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,i,j;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    cin>>m;
    int b[m];
    for(j=0;j<m;j++){
        cin>>b[j];
    }
    for(i=0,j=0;i<n,j<m;i++,j++){
    if((a[i]+b[j])!=a[i]||(a[i]+b[j])!=b[j]){
        cout<<a[i]<<" "<<b[i]<<endl;
        break;
    }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void solve(int n,int a[],int m,int b[]){
    int ok=0,ok1=0,x,y;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int sum=a[i]+b[j];
            for(int i=0;i<n;i++){
                if(sum!=a[i]){
                    ok=1;
                }
            }
            for(int i=0;i<m;i++){
                if(sum!=b[i]){
                    ok1=1;
                }
            }
            if(ok==1 && ok1==1){
                  x=a[i],y=b[j];
            cout<<x<<" "<<y<<endl;
        break;
            }
        }
    }
}
int main(){
  int n,m;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cin>>m;
  int b[m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  solve(n,a,m,b);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
void solve(int n,int a[],int m,int b[]){
    int ok=0,ok1=0,x,y,ok2=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int sum=a[i]+b[j];
               x=a[i],y=b[j];
            for(int i=0;i<n;i++){
                if(sum!=a[i]){
                    ok=1;
                }
            }
            for(int i=0;i<m;i++){
                if(sum!=b[i]){
                    ok1=1;
                }
            }
            if(ok==1 && ok1==1){
                  ok2=1;
                   break;
            }
        }
        if(ok2==1){
            break;
        }
    }
    cout<<x<<" "<<y<<endl;
}
int main(){
  int n,m;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cin>>m;
  int b[m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  solve(n,a,m,b);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
void solve(int n,int a[],int m,int b[]){
    int ok=0,ok1=0,x,y;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int sum=a[i]+b[j];
            for(int i=0;i<n;i++){
                if(sum!=a[i]){
                    ok=1;
                }
            }
            for(int i=0;i<m;i++){
                if(sum!=b[i]){
                    ok1=1;
                }
            }
            if(ok==1 && ok1==1){
                  x=a[i],y=b[j];
            }
        }
        cout<<x<<" "<<y<<endl;
        break;
    }
}
int main(){
  int n,m;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cin>>m;
  int b[m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  solve(n,a,m,b);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,m;
    cin>>n;
    vector<ll>v1;
    vector<ll>v2;
    vector<ll>v3;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        ll y;
        cin>>y;
        v2.pb(y);
    }
//    n=max(n,m);
    ll flag=0,flag1=0;
    for(ll i=0; i<n; i++)
    {
        for(ll j=0; j<m; i++)
        {
            ll z;
            z=v1[i]+v2[j];
            for(ll q=0; q<n; q++)
            {
                if(z!=v1[q])
                {
                    flag=1;
                    break;
                }
            }
            for(ll r=0; r<m; r++)
            {
                if(z!=v2[r])
                {
                    flag1=1;
                }
            }
            if(flag==1&&flag1==1)
            {
                cout<<v1[i]<<" "<<v2[j]<<endl;
                return 0;
            }

        }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,m;
    cin>>n;
    vector<ll>v1;
    vector<ll>v2;
    vector<ll>v3;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        ll y;
        cin>>y;
        v2.pb(y);
    }
//    n=max(n,m);
    ll flag=0,flag1=0;
    for(ll i=0; i<n; i++)
    {

        for(ll j=0; j<m; i++)
        {
            flag=0,flag1=0;
            ll z;
            z=v1[i]+v2[j];
            for(ll q=0; q<n; q++)
            {
                if(z!=v1[q])
                {
                    flag=1;
                    break;
                }
                else
                    flag=0;
            }
            for(ll r=0; r<m; r++)
            {
                if(z!=v2[r])
                {
                    flag1=1;
                    break;
                }
                else
                    flag1=0;
            }
            if(flag==1&&flag1==1)
            {
                cout<<v1[i]<<" "<<v2[j]<<endl;
                return 0;
            }

        }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,m;
    cin>>n;
    vector<ll>v1;
    vector<ll>v2;
    vector<ll>v3;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        ll y;
        cin>>y;
        v2.pb(y);
    }
    ll flag=0,flag1=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
           ll sum=v1[i]+v2[j];
           for(ll q=0,r=0;q<n,r<m;q++,r++)
           {
               if(sum!=v1[q]&&sum!=v2[q])
               {
                   cout<<v1[i]<<" "<<v2[j]<<endl;
                   return 0;
               }
           }
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,m;
    cin>>n;
    vector<ll>v1;
    vector<ll>v2;
    vector<ll>v3;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        ll y;
        cin>>y;
        v2.pb(y);
    }
//    n=max(n,m);
    ll flag=0,flag1=0;
    for(ll i=0; i<n; i++)
    {
        for(ll j=0; j<m; i++)
        {
            ll z;
            z=v1[i]+v2[j];
            for(ll q=0; q<n; q++)
            {
                if(z!=v1[q])
                {
                    flag=1;
                    break;
                }
            }
            for(ll r=0; r<m; r++)
            {
                if(z!=v1[r])
                {
                    flag1=1;
                }
            }
            if(flag==1&&flag1==1)
            {
                cout<<v1[i]<<" "<<v2[j]<<endl;
                return 0;
            }

        }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,m;
    cin>>n;
    vector<ll>v1;
    vector<ll>v2;
    vector<ll>v3;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        ll y;
        cin>>y;
        v2.pb(y);
    }
    ll flag=0,flag1=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            for(ll q=0;q<n;q++)
            {
                if((v1[i]+v2[j])!=v1[q])
                {
                   for(ll r=0;r<m;r++)
                   {
                       if((v1[i]+v2[j])!=v2[r])
                       {
                           cout<<v1[i]<<" "<<v2[j]<<endl;
                           return 0;
                       }
                   }
                }
            }
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,m;
    cin>>n;
    vector<ll>v1;
    vector<ll>v2;
    vector<ll>v3;
    for(ll i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        v1.pb(x);
    }
    cin>>m;
    for(ll i=0; i<m; i++)
    {
        ll y;
        cin>>y;
        v2.pb(y);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    cout<<v1[n-1]<<" "<<v2[m-1]<<endl;

}


#include <iostream>

using namespace std;
int main()
{
    int A[101], B[101];
    int n, m, a = 0, b = 0, sum = 0, flag = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> A[i];
    cin >> m;
    for (int i = 1; i <= m; i++)
        cin >> B[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            flag = 0;
            sum = A[i] + B[j];
            for (int k = 1; k <= n; k++)
            {
                if (sum == A[k])
                {
                    flag = 1;
                    break;
                }
            }
            for (int k = 1; k <= m; k++)
            {
                if (sum == B[k])
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
            {
                a = A[i];
                b = B[j];
                break;
            }
        }
        if (flag == 0) { break; }
    }
    cout << a << " " << b << endl;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0 , flag = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    flag = 0 ;
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    flag = 0 ;
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0 , flag = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                        break ;
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                        break ;
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}

/*#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    a = A[i] ;
                    b = B[j] ;
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    a = A[i] ;
                    b = B[j] ;
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}*/


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0 , flag = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                flag = 0 ;
                if (sum != A[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                flag = 0 ;
                if (sum != B[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0 , flag = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                        break ;
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                        break ;
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    a = A[i] ;
                    b = B[j] ;
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    a = A[i] ;
                    b = B[j] ;
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0 , flag = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum == A[k])
                    break ;
                else
                {
                    a = A[i] ;
                    b = B[i] ;
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum == B[k])
                    break ;
                else
                {
                    a = A[i] ;
                    b = B[i] ;
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <iostream>

using namespace std;
int main()
{
    int A[101] , B[101] ;
    int n , m , a = 0 , b = 0 , sum = 0 , flag = 0;
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> A[i] ;
    cin >> m ;
    for (int i = 1 ; i <= m ; i++)
        cin >> B[i] ;
    for (int i = 1 ; i <= n ; i++)
    {
        for ( int j = 1 ; j <= m ; j++)
        {
            sum = A[i] + B[j] ;
            for ( int k = 1 ; k <= n ; k++)
            {
                if (sum != A[k])
                {
                    flag = 0
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
            for ( int k = 1 ; k <= m ; k++)
            {
                if (sum != B[k])
                {
                    flag = 0
                    if (flag == 0)
                    {
                        a = A[i] ;
                        b = B[j] ;
                    }
                    else
                    {
                        flag = 1 ;
                        break ;
                    }
                }
            }
        }
    }
    cout << a << " " << b << endl ;

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

#define deb(a)    cout<<__LINE__<<"# "<<#a<<" -> "<<a<<endl;
#define pb push_back
#define OO 2e9+10

#define ConPnt(a)   {for(auto it: a){cout<<it<<", ";}cout<<endl;}
#define MapPnt(a)   {for(auto it: a){cout<<it.first<<": "<<it.second<<", ";}cout<<endl;}

typedef long long ll;
typedef pair<int,int>pii;

template<class T> T abs(T x){
    if(x<0) return -x;
    return x;
}
template<class T>T sqr(T a){
    return a*a;
}

const double pi = acos(-1.0);
const double eps = 1e-8;

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int ar[1100];
    int br[1100];
    map<int,int>mp;
    int i,j,n,m;
    while(1==scanf("%d",&n))
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&ar[i]);
            mp[ar[i]]++;
        }
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            scanf("%d",&br[i]);
            mp[br[i]]++;
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                if(mp[ar[i]+br[j]]==0)
                    break;
            if(mp[ar[i]+br[j]]==0)
                break;
        }
        printf("%d %d\n",ar[i],br[j]);

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int ar1[200];
int ar2[200];
int ar[20000];
int n,m;
int main(){
     cin>>n;
     for(int i=0;i<n;i++){
         cin>>ar1[i];
         ar[ar1[i]]=1;
     }
     cin>>m;
     for(int i=0;i<m;i++){
         cin>>ar2[i];
         ar[ar2[i]]=1;
     }
     for(int i=0;i<n;i++){
         for(int j=0;j<m;j++){
             int x =ar1[i]+ar2[j];
           if(ar[x]!=1){
              cout<<ar1[i]<<" "<<ar2[j]<<"\n";
              return 0;
           }
         }
     }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

#define deb(a)    cout<<__LINE__<<"# "<<#a<<" -> "<<a<<endl;
#define pb push_back
#define OO 2e9+10

#define ConPnt(a)   {for(auto it: a){cout<<it<<", ";}cout<<endl;}
#define MapPnt(a)   {for(auto it: a){cout<<it.first<<": "<<it.second<<", ";}cout<<endl;}

typedef long long ll;
typedef pair<int,int>pii;

template<class T> T abs(T x){
    if(x<0) return -x;
    return x;
}
template<class T>T sqr(T a){
    return a*a;
}

const double pi = acos(-1.0);
const double eps = 1e-8;

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int ar[110];
    int br[110];
    map<int,int>mp;
    int i,j,n,m;
    while(1==scanf("%d",&n))
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&ar[i]);
            mp[ar[i]]++;
        }
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            scanf("%d",&br[i]);
            mp[br[i]]++;
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                if(mp[ar[i]+br[j]]==0)
                    break;
            if(mp[ar[i]+br[j]]==0)
                break;
        }
        printf("%d %d\n",ar[i],br[j]);
        mp.clear();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,p,q;
    cin>>n;
    int ara[10000],arr[10000];
    for(int i=0; i<n; i++)
        cin>>ara[i];

    sort(ara,ara+n);

    cin>>m;
    for(int i=0; i<m; i++)
        cin>>arr[i];

    sort(arr,arr+m);

    p = ara[n-1];
    q = arr[m-1];
    cout<<p<<' '<<q<<endl;

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

#define deb(a)    cout<<__LINE__<<"# "<<#a<<" -> "<<a<<endl;
#define pb push_back
#define OO 2e9+10

#define ConPnt(a)   {for(auto it: a){cout<<it<<", ";}cout<<endl;}
#define MapPnt(a)   {for(auto it: a){cout<<it.first<<": "<<it.second<<", ";}cout<<endl;}

typedef long long ll;
typedef pair<int,int>pii;

template<class T> T abs(T x){
    if(x<0) return -x;
    return x;
}
template<class T>T sqr(T a){
    return a*a;
}

const double pi = acos(-1.0);
const double eps = 1e-8;

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int ar[1100];
    int br[1100];
    map<int,int>mp;
    int i,j,n,m;
    while(1==scanf("%d",&n))
    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&ar[i]);
            mp[ar[i]]++;
        }
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            scanf("%d",&br[i]);
            mp[br[i]]++;
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
                if(mp[ar[i]+br[j]]==0)
                    break;
            if(mp[ar[i]+br[j]]==0)
                break;
        }
        printf("%d %d\n",ar[i],br[j]);
        mp.clear();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
//const int INF=1e9+5;
int main()
{
	int n,m,;
	int a=0;
	int t=0;
	int b=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		{
			cin>>a;
			a=max(a,t);
		}
	cin>>m;
	int b[m];
	for(int i=0;i<m;i++)
		{
			cin>>b;
			b=max(b,t);
		}

	cout<<a<<" "<<b;
}


#include<bits/stdc++.h>
using namespace std;
//const int INF=1e9+5;
int main()
{
	int n,m,;
	int a[n],B[m];
	int a=0;
	int t=0;
	int b=0;
	cin>>n;
	for(int i=0;i<n;i++)
		{
			cin>>a;
			a=max(a,t);
		}
	cin>>m;
	for(int i=0;i<m;i++)
		{
			cin>>b;
			b=max(b,t);
		}

	cout<<a<<" "<<b;
}


#include<bits/stdc++.h>
using namespace std;
//const int INF=1e9+5;
int main()
{
	int n,m;
	int a=0;
	int t=0;
	int b=0;
	cin>>n;
	for(int i=0;i<n;i++)
		{
			cin>>a;
			a=max(a,t);
		}
	cin>>m;
	//int b[m];
	for(int i=0;i<m;i++)
		{
			cin>>b;
			b=max(b,t);
		}

	cout<<a<<" "<<b;
}


#include<bits/stdc++.h>
using namespace std;
//const int INF=1e9+5;
int main()
{
	int n,m,;
	int a=0;
	int t=0;
	int b=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		{
			cin>>a;
			a=max(a,t);
		}
	cin>>m
	int b[m];
	for(int i=0;i<m;i++)
		{
			cin>>b;
			b=max(b,t);
		}

	cout<<a<<" "<<b;
}


#include<bits/stdc++.h>
using namespace std;
//const int INF=1e9+5;
int main()
{
	int n,m;
	int a=0;
	int t=0;
	int b=0;
	cin>>n;
	for(int i=0;i<n;i++)
		{
			cin>>a;
			a=max(a,t);
		}
	cin>>m
	//int b[m];
	for(int i=0;i<m;i++)
		{
			cin>>b;
			b=max(b,t);
		}

	cout<<a<<" "<<b;
}


#include<bits/stdc++.h>
using namespace std;
//const int INF=1e9+5;
int main()
{
	int n,m;
	int a=0;
	int t=0;
	int b=0;
	cin>>n;
	for(int i=0;i<n;i++)
		{
			cin>>t;
			a=max(a,t);
		}
	cin>>m;
	//int b[m];
	for(int i=0;i<m;i++)
		{
			cin>>t;
			b=max(b,t);
		}

	cout<<a<<" "<<b;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n,m,m1=0,m2=0;
     cin>>n;
     int a[n],b[m];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
         if(a[i]>m1)
            m1=a[i];
     }
     cin>>m;
     for(int j=0;j<m;j++)
     {
         cin>>b[j];
         if(b[j]>m2)
            m2=b[j];
     }
     cout<<m1<<" "<<m2;


#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n,m,x=0,y=0;
     cin>>n;
     int a[n];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
         if(a[i]>x)
            x=a[i];
     }
     cin>>m;
     int b[m];
     for(int j=0;j<m;j++)
     {
         cin>>b[j];
         if(b[j]>y)
            y=b[j];
     }
     cout<<x<<" "<<y;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n,m;
     cin>>n;
     int a[n],b[m];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     cin>>m;
     for(int j=0;j<m;j++)
     {
         cin>>b[j];
     }
     sort(a,a+n);
     sort(b,b+n);
     cout<<a[n-1]<<" "<<b[m-1];

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n,m;
     cin>>n;
     int a[n],b[m];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     cin>>m;
     for(int j=0;j<m;j++)
     {
         cin>>b[j];
     }
     sort(a,a+n);
     sort(b,b+n);
     cout<<a[n-1]<<" "<<b[n-1];

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
     int n,m;
     cin>>n;
     int a[n],b[m];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     cin>>m;
     for(int j=0;j<m;j++)
     {
         cin>>b[j];
     }
     sort(a,a+n);
     sort(b,b+m);
     cout<<a[n-1]<<" "<<b[m-1];

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  int a[n],b[m];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(int j=0;j<n;j++)
  {
      cin>>b[j];
  }
  sort(a,a+n);
  sort(b,b+m);
  int k=max(n,m);
  int x=0,y=0,z1=1,z2=1;
  while(k--)
  {
      int c=a[x]+b[y];
      for(int i=0;i<n;i++)
      {
         if(c==a[i])
         {
             z1=0;
             x++;
             break;
         }
      }
      if(z1==0)
      {
          z1=1;
          continue;
      }
       for(int j=0;j<m;j++)
      {
         if(c==b[j])
         {
             z2=0;
             y++;
             break;
         }
      }
      if(z2==0)
      {
          z2=1;
          continue;
      }
      if(z1==1 &&z2==1)
      {
          cout<<a[x]<<" "<<b[y];
          break;
      }
      z1=1;
      z2=1;

  }

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
    ll n,m;
    cin>>n>>m;
    ll ma=0,mb=0;
    ll a[n],b[m];
    for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(ma,a[i]);
    }
    for(int i=0;i<m;i++){
    cin>>b[i];
    mb=max(mb,b[i]);
    }
    cout<<ma<<" "<<mb;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
    ll n,m; ll p;
    cin>>n>>m;
    ll ma=0,mb=0;
    ll a[n],b[m];
    for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(ma,a[i]);
    }
    for(int i=0;i<m;i++){
    cin>>b[i];
    mb=max(mb,b[i]);
    }
    cout<<ma<<" "<<mb;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
    ll n,m;
    cin>>n>>m;
    ll ma==0,mb=0;
    for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(ma,a[i]);
    }
    for(int i=0;i<m;i++){
    cin>>b[i];
    mb=max(mb,b[i]);
    }
    cout<<ma<<" "<<mb;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
    ll n,m;
    cin>>n>>m;
    ll ma=0,mb=0;
    for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(ma,a[i]);
    }
    for(int i=0;i<m;i++){
    cin>>b[i];
    mb=max(mb,b[i]);
    }
    cout<<ma<<" "<<mb;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
    ll n,m;
    cin>>n;
    ll ma=0,mb=0;
    ll a[n];
    //b[m];
    for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(ma,a[i]);
    }
    cin>>m;
    ll b[m];
    for(int i=0;i<m;i++){
    cin>>b[i];
    mb=max(mb,b[i]);
    }
    cout<<ma<<" "<<mb;
}


#include <bits/stdc++.h>
using namespace std;
int a[1000],b[1000];

int main()
{
   int n,m,j=0,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++) cin>>a[i];
   sort(a,a+n);
   cin>>m;
   for(int i=0;i<m;i++) cin>>b[i];
   sort(b,b+n);

   cout<<a[n-1]<<" "<<b[m-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[1000],b[1000];

 bool search_num(int c[], int n, int x)
 {
     for(int i=0;i<n;i++)
     {
         if(c[i]==x) return true;

     }
     return false;
 }
int main()
{
   int n,m,j=0,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++) cin>>a[i];
   sort(a,a+n);
   cin>>m;
   for(int i=0;i<m;i++) cin>>b[i];
   sort(b,b+m);
   for(int j=0;j<n;j++)
   for(int i=0;i<m;i++)
   {
       if(!(search_num(b,m,a[j]+b[i]))&&!(search_num(a,n,a[j]+b[i])))
       {
          x=a[j];
          y=b[i];
          goto end1;
       }
   }
  end1: cout<<x<<" "<<y<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[1000],b[1000];

int main()
{
   int n,m,j=0,x=0,y=0;
   cin>>n;
   for(int i=0;i<n;i++) cin>>a[i];
   sort(a,a+n);
   cin>>m;
   for(int i=0;i<m;i++) cin>>b[i];
   sort(b,b+m);

   cout<<a[n-1]<<" "<<b[m-1]<<endl;
    return 0;
}