#include <bits/stdc++.h>
using namespace std;
int i, j;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string res1 = "", res2 = "";
    bool flag = false;
    for (char c : s) {
      if (c == '0') {
        res1 += '0';
        res2 += '0';
        continue;
      }
      if (c == '2') {
        if (flag) {
          res1 += '2';
          res2 += '0';
        } else {
          res1 += '1';
          res2 += '1';
        }
      } else {
        if (flag) {
          res1 += '1';
          res2 += '0';
        } else {
          res1 += '0';
          res2 += '1';
          flag = true;
        }
      }
    }
    cout << res1 << '\n' << res2 << '\n';
  }
}
