#include<iostream>
#include<vector>

int main(){
	int n;
	std::cin >> n;
	while (n){
		std::vector<int> ball(10);
		for (int i = 0; i < 10; ++i)std::cin >> ball[i];
		int cnt = 0;
		for (int i = 1; i < 10; ++i){
			if (ball[i] < ball[0])cnt++;
		}
		if (cnt < 3)std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
		n--;
	}
	return 0;
}