#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 1e6 + 50;
int T, n; char S[N];
int a[N], b[N];
void Main(){
	scanf("%s", S + 1);
	n = strlen(S + 1);
	for(int i = 1, s = n; i <= n; i++){
		if(S[i] == '0') ++a[s], ++s; 
		if(S[i] == '1') ++b[s], --s;
	} int t = n; 
	while(true){
//		cout << "FF " << t << " " << a[t] << endl;
		bool ok = a[t] && (b[t + 1] || !b[t]);
		if(ok) putchar('0'), --a[t], ++t;
		else if(b[t]) putchar('1'), --b[t], --t;
		else break;
	} puts("");
//	for(int i = 0; i <= n + n; i++) cout << a[i] << " "; cout << endl;
//	for(int i = 0; i <= n + n; i++) cout << b[i] << " "; cout << endl;
}
int main(){
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	cin >> T;
	while(T--) Main();
	return 0;
} 