#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 4, mod = 1e9 + 7;
void _accepted_by_one_hit_() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  _accepted_by_one_hit_();
  int test;
  cin >> test;
  while (test--) {
    int n;
    string s, s1 = "", s2 = "";
    cin >> n >> s;
    bool ok = false;
    for (auto c : s) {
      if (c == '2') {
        if (ok) {
          s1 += '2';
          s2 += '0';
        } else {
          s1 += '1';
          s2 += '1';
        }
      }
      if (c == '1') {
        if (!ok) {
          s1 += '0';
          s2 += '1';
          ok = true;
        } else {
          s1 += '1';
          s2 += '0';
        }
      }
      if (c == '0') {
        s1 += '0';
        s2 += '0';
      }
    }
    cout << s1 << endl;
    cout << s2 << "\n";
  }
}
