#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

const int MAXN = 1000010;
const int BASE = 500000;

int l[MAXN], r[MAXN];

void dfs(int now, string& ans) {
  while (r[now] > 0) {
    --r[now];
    dfs(now + 1, ans);
    ans.push_back('0');
  } 
  while (l[now] > 0) {
    --l[now];
    dfs(now - 1, ans);
    ans.push_back('1');
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int times;
  cin >> times;
  while (times--) {
    string s;
    cin >> s;
    for (int i = BASE - s.size(); i <= BASE + s.size(); ++i) {
      l[i] = r[i] = 0;
    }
    int now = BASE;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '0') {
        ++r[now];
        ++now;
      } else {
        ++l[now];
        --now;
      }
    }
    string anss;
    dfs(BASE, anss);
    reverse(anss.begin(), anss.end());
    cout << anss << endl;
  }
  return 0;
}