#include<bits/stdc++.h>
using namespace std;
#define ros \
freopen("input.txt","r",stdin);\
freopen("output.txt","w",stdout);
#define disable_c_cpp_integration ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);// printf buffer > cout buffer
#define deb1(x) cout<<#x<<" : "<<x<<"\n"
#define deb2(x,y) cout<<#x<<":"<<x<<"   "<<#y<<":"<<y<<"\n"
#define ll long long // upto 9 * 10^18
#define ld long double // upto 10^5
#define eps 1e-9
#define rep(i,start,end) for(int i=start;i<end;i++) 
#define per(i,start,end) for(int i=start;i>end;i++) 
//fast input.....
#define inpi(x) scanf("%d",&x);
#define inpf(x) scanf("%f",&x);
#define inpc(x) scanf("%c",&x);
#define inps(x) scanf("%s",&x);
#define inpll(x) scanf("%lld",&x);
#define inpld(x) scanf("%ld",&x);
// input and output by cin and cout.....


typedef vector<int> vi;
typedef pair<int,int> pi;
const int mod9=1e9+7;


void solve()
{
string s;
cin>>s;
int f0=1,f1=1,f2=1,k=-1,l=-1;
for(int i=0;i<s.length()-1;i++)
{
    if(!f1 && i>k)
    {
        if(s[i]=='0')
        {
            if(i-k<2)f2=0;
        }
    }
    if(s[i]=='0' && s[i+1]=='0')
    {
        f0=0;
        l=i-1;
    }
    else if(s[i]=='1' && s[i+1]=='1')
    {
        f1=0;
        k=i+2;
    }
    
}
for(int i=0;i<l;i++)
{
    if(s[i]=='1' && s[i+1]=='1')
    {
        cout<<"NO";
        return;
    }
}

// deb2(f0,f1);
if(f0 || f1)cout<<"YES";
else
{
    if(is_sorted(s.begin(),s.end()))cout<<"YES";
    else if(f2)cout<<"YES";
    else
    cout<<"NO";
}

}


int main()
{
//disable_c_cpp_integration;
ll t;
cin>>t;
ll test_case_number=t;
while(t--)
{
solve();
//cout<<"Case #"<<test_case_number-t<<": "<<solve();
cout<<"\n";
}
return 0;
}