#include <bits/stdc++.h>
using namespace std;
const long long linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans1, ans2;
    bool elf = false;
    for (int i = 0; i < (n); ++i) {
      if (elf) {
        if (s[i] == '2') ans1 += '0', ans2 += '2';
        if (s[i] == '0') ans1 += '0', ans2 += '0';
        if (s[i] == '1') ans1 += '0', ans2 += '1';
      } else {
        if (s[i] == '2') ans1 += '1', ans2 += '1';
        if (s[i] == '0') ans1 += '0', ans2 += '0';
        if (s[i] == '1') {
          ans1 += '1', ans2 += '0';
          elf = true;
        }
      }
    }
    cout << ans1 << endl << ans2 << endl;
  }
  return 0;
}
