#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long p;
  cin >> p;
  while (p--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    string s1, s2;
    bool degla = false;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '2') {
        if (degla) {
          s1.push_back('0');
          s2.push_back('2');
        } else {
          s1.push_back('1');
          s2.push_back('1');
        }
      }
      if (s[i] == '0') {
        s1.push_back('0');
        s2.push_back('0');
      } else if (s[i] == '1') {
        if (degla) {
          s1.push_back('0');
          s2.push_back('1');
        } else {
          degla = true;
          s1.push_back('1');
          s2.push_back('0');
        }
      }
    }
    cout << s1 << "\n" << s2 << "\n";
  }
  return 0;
}
