#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{
	ll t,n,s,f1,f2,i;
	cin>>t;
	while(t--)
	{
	    string s;
	    cin>>s;
	    n=s.length();
	    f1=f2=0;
	    for(i=1;i<n;i++)
	    {
	      if(s[i]=='1'&&s[i-1]=='1')
	      f1=1;
	      if(f1 && s[i]=='0' && s[i-1]=='0')
	      {
	          f2=1;
	          break;
	      }
	    }
	    if(f1&&f2)
	    cout<<"NO\n";
	    else
	    cout<<"YES\n";
	}
	return 0;
}