#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct ch{
char k;
ch *next,*fa;
};
struct ch *root;
void init(ch *&t){
t=(ch *)malloc(sizeof(ch));
t->next=NULL;
t->fa=NULL;
}
char str[1005];
void deal(){
int NumberTrue=0;//记录前面有多少个"0"
struct ch *t=root,*h;
while(t->next!=NULL){
t=t->next;
if(t->k=='0'){
NumberTrue++;
}
else
{
if(NumberTrue>=2){//出现了"001"的情况,变成"0"
NumberTrue--;
h=t->fa->fa;
if(t->next!=NULL)
t->next->fa=h;
h->next=t->next;
}
else
break;
}
}
if(root->next->k=='0' && root->next->next==NULL)//只剩下"0"
printf("Yes\n");
else
printf("No\n");
free(root);
}
void make(){
scanf("%s",str);
init(root);
struct ch *t=root;
int i;
int n=strlen(str);
for(i=0;i<n;i++){
struct ch *h;
init(h);
h->k=str[i];
h->fa=t;
t->next=h;
t=h;
}
t->next=NULL;
deal();
}
int main(){
scanf("%d",&t);
while(t--){
make();
}
return 0;
}