#include<iostream>
int main() {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i += 1) {
		int N[10];
		for (int i = 0; i < 10; i += 1) 
			std::cin >> N[i];
		if ((N[0] == 1 || N[1] == 1)&&(N[8]==10||N[9]==10))
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
	return 0;
}