#include <bits/stdc++.h>
using namespace std;
bool check0possible(string &s){
    int lastindice=-2;
   int continous0=INT_MIN,continous1=INT_MAX;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]=='0'){
            if(s[i+1]=='0'){
                
                continous0 =i;
            }
        }else{
            if(s[i]=='1'){
                if(s[i+1]=='1'){
                    if(continous1==INT_MAX)
                    continous1 = i;
                    
                }
            }
        }
    }
    // cout << continous1 << continous0<<endl;
    if(continous1==INT_MAX||continous0==INT_MIN)
    return true;
    if(continous1<continous0)
    return false;
    return true;
}
int main() {
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        if(check0possible(s))
        cout << "YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
	// your code goes here
	return 0;
}
