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

int main() {
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int f=0,f1=0;
        for (int i = 1; i < s.length(); i++) 
        {
            if(s[i]==s[i-1] && s[i-1]=='1')f=1;
            if(s[i]==s[i-1] && s[i-1]=='0' && f==1)f1=1;
        }
            
        if(f1==1)
        {
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"YES"<<endl;
        }
    
        
    }
	return 0;
}