#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
const int mod = 1e9 + 7;
int t, n;
int ma[maxn], mi[maxn];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t) {
    cin >> n;
    cin >> s;
    int cnt = 1;
    for (int i = 0; i < n; i++) {
      if (s[i] == '2') {
        mi[i] = 1;
        ma[i] = 1;
        cnt++;
      }
      if (s[i] == '0') {
        mi[i] = 0;
        ma[i] = 0;
        cnt++;
      }
      if (s[i] == '1') {
        mi[i] = 0;
        ma[i] = 1;
        cnt++;
        break;
      }
    }
    for (int i = cnt - 1; i < n; i++) {
      if (s[i] == '1') mi[i] = 1;
      if (s[i] == '2') mi[i] = 2;
      if (s[i] == '0') mi[i] = 0;
      ma[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      cout << ma[i];
    }
    cout << "\n";
    for (int i = 0; i < n; i++) {
      cout << mi[i];
    }
    cout << "\n";
    t--;
  }
  return 0;
}
