#include <bits/stdc++.h>
using namespace std;
 
// hàm tìm số lớn thứ 1
int max1N (int a[], int n) {
	int tmp=-1e9;
	for (int i=0; i<n; i++) {
		if (a[i]>tmp) tmp= a[i];
	}
	return tmp;
}
 
// hàm tìm số lớn thứ 2
int max2N (int a[], int n, int res1) {
	int tmp=-1e9;
	for (int i=0; i<n; i++) {
		if (a[i]>tmp && a[i]<res1) tmp= a[i];
	}
	return tmp;
}
 
int main () {
	ios_base:: sync_with_stdio(false);
	cin.tie(nullptr);
 
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		int a[n];
		for (int i=0; i<n; i++) cin >> a[i];
 
		int res1= max1N (a, n);
		int res2= max2N (a, n, res1);
 
		// nếu không tìm được res2 -> res2 mặc định là -1e9
		if (res2==-1e9) cout << "0" << endl;
		else cout << res2 << " " << res1 << endl;
	}
}