#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a);i<=(b);i++)
#define drep(i,a,b) for (register int i=(a);i>=(b);i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
inline ll read()
{
	ll sum=0,f=0;char c=getchar();
	while (!isdigit(c)) f|=(c=='-'),c=getchar();
	while (isdigit(c)) sum=(sum<<1)+(sum<<3)+(c^48),c=getchar();
	return f?-sum:sum;
}

const int N=1000010;
int cnt[N<<1],T,n;
char c[N];

void solve()
{
	scanf("%s",c+1),n=strlen(c+1);
	for (int i=1,now=0;i<=n;i++)
	{
		if (c[i]=='1') cnt[N+now]++,now++;
		if (c[i]=='0') now--,cnt[N+now]++;
	}
	
	for (int i=1,now=0;i<=n;i++)
	{
		if (cnt[N+now-1]&&(!cnt[N+now]||cnt[N+now-1]>1)) putchar('0'),now--,cnt[N+now]--;
		else putchar('1'),cnt[N+now]--,now++;
	}
	putchar('\n');
}

int main()
{
	drep(T,read(),1) solve();
}