#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <ctime>

using namespace std;

const int maxN = 1001000;
int cntzero[maxN];
int cntone[maxN];
const int ZERO = 500005;

void solve() {
	string s;
	cin >> s;

	int n = s.length();

	for (int i = ZERO - n; i <= ZERO + n; ++i) {
		cntzero[i] = 0;
		cntone[i] = 0;
	}

	int curx = ZERO;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '0') {
			++cntzero[curx];
			++cntone[curx + 1];
			++curx;
		}
		else {
			++cntone[curx];
			++cntzero[curx - 1];
			--curx;
		}
	}

	string res = "";

	int v = ZERO;

	while (true) {
		if (cntzero[v] > 0 && !(cntzero[v] == 1 && cntone[v] > 0)) {
			res += '0';
			--cntzero[v];
			--cntone[v + 1];
			++v;
			continue;
		}
		else if (cntone[v] > 0) {
			res += '1';
			--cntone[v];
			--cntzero[v - 1];
			--v;
			continue;
		}
		else {
			break;
		}
	}
	cout << res << endl;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	//t = 1;


	for (int tt = 0; tt < t; ++tt) {
		solve();
	}




	return 0;

}