#include <iostream>
using namespace std;
int main(){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		b=0;c=0;f=true;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b<a&&c<a){
				if(b<c)c=a;
				else b=a;
			}
			else if(b<a)b=a;
			else if(c<a)c=a;
			else f=false;
			cout<<b<<" "<<c<<endl;
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}