#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 500000
using namespace std;
int T,n;
char s[maxn+5]; 
int sum[maxn+5]; 

struct myarray{
	int c[maxn*2+5];
	inline int & operator [](int i){return c[i+maxn];} 
}E;
int stk[maxn+5],top; 
void dfs(int x){
	while(E[x]){
		E[x]--;
		dfs(x+1);
	}
	while(E[x-1]){
		E[x-1]--;
		dfs(x-1);
	}
	stk[++top]=x;
}
int main(){
	scanf("%d",&T); 
	while(T--){
		scanf("%s",s+1);
		n=strlen(s+1);
		for(int i=-n;i<=n;i++) E[i]=0; 
		for(int i=1;i<=n;i++){
			sum[i]=sum[i-1]+(s[i]=='0'?1:-1);
			E[min(sum[i],sum[i-1])]++;
		} 
		top=0;
		dfs(0);
		int x=0,y;
		for(int i=top-1;i>0;i--,x=y){
			y=stk[i];
			if(x+1==y) putchar('0');
			else putchar('1');  
		}
		putchar('\n');
	}
}