#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    char x;
    string a = "", b = "";
    bool seen1 = false;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (seen1) {
        a += x;
        b += '0';
      } else {
        if (x == '2') {
          a += '1';
          b += '1';
        } else if (x == '1') {
          if (!seen1) seen1 = true;
          a += '0';
          b += '1';
        } else {
          a += '0';
          b += '0';
        }
      }
    }
    cout << a << "\n";
    cout << b << "\n";
  }
  return 0;
}
