#include<bits/stdc++.h>
#define FOR(i,a,b) for( int i=(a); i<(b); ++i)
#define REP(i,a,b) for( int i=(a); i<=(b); ++i)
#define SHOW(x) for(auto i:(x)){ cout << i << ' ';} cout << endl;
#define MAXN 25
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
void solve(){
    string s;cin >> s;
    bool f1 = false,f2 = false;
    for(int i = 1; i < s.size(); i++){
        if(s[i] == s[i-1] && s[i] == '1'){
            f1 = true;
        }
        if(f1 && s[i] == s[i-1] && s[i] == '0'){
            f2 = true;
            break;
        }
    }
    if(f2) cout << "NO" << endl;
    else cout << "YES" << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    while(n--){
        solve();
    }
    return 0;
}    