#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string tmp1 = "", tmp2 = "";
  bool t = false;
  for (char c : s) {
    if (c == '2') {
      if (t || tmp1 > tmp2) {
        tmp1 += '0', tmp2 += '2';
        t = true;
      } else
        tmp1 += '1', tmp2 += '1';
    }
    if (c == '0') tmp1 += '0', tmp2 += '0';
    if (c == '1') {
      if (t || tmp1 > tmp2) {
        tmp2 += '1', tmp1 += '0';
        t = true;
      } else
        tmp1 += '1', tmp2 += '0';
    }
  }
  cout << tmp1 << "\n" << tmp2 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
