#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;
using ll = long long;

#define mod	1000000007
#define inf	1e18
#define g_substring(i,j)	substr(i,j-i)

void run_case(){
	string curr;
	cin>>curr;
	map<int,int> graph;
	int node = 0;
	for (char word:curr){
		if (word == '0'){
			graph[--node] += 1;	
		}else{
			graph[node++] += 1;
		}
	}
	node = 0;
	for(int index = 0; index < curr.size(); index+=1){
		if (graph[node] == 0){
			cout<<"0";
			graph[--node] -= 1;
		}else if (graph[node-1] <= 1){
			cout<<"1";
			graph[node++] -= 1;
		}else{
			cout<<"0";
			graph[--node] -= 1;
		}
	}
	cout << "\n";
}	

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n;
	cin>>n;
	
	while (n-- > 0){
		run_case();
	}
	return 0;
}
