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

#define endl '\n'

using ll = long long;

void test_case() {
	std::string s;
	cin >> s;
	
	int n = s.size();
	vector<int> count(2);
	for (auto && c : s) {
		count[c-'0']++;
	}
	
	if (not count[0] or not count[1]) {
		cout << "YES" << endl;
		return;
	}
	
	bool solved = true;
	bool ones = false;
	for (int i = 0; i < n; ++i) {
		if (ones) {
			if (s[i] == '1') {
				continue;
			}
			
			if (i + 1 == n) {
				break;
			}
			
			if (s[i + 1] == '0') {
				solved = false;
				break;
			}
		} else {
			if (s[i] == '0') {
				continue;
			}
			
			if (i + 1 == n) {
				break;
			}
			
			if (s[i + 1] == '0') {
				i++;
			} else {
				ones = true;
			}
		}
	}
	
	
	if (solved) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int tests;
	cin >> tests;
	
	for (int i=0;i<tests;++i) {
		test_case();
	}
	return 0;
}


