#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string q;
    cin >> q;
    string small = "1", big = "1";
    int ind = -1;
    for (int i = 1; i < n; i++) {
      if (q[i] == '0') {
        small = small + '0';
        big = big + '0';
      } else if (q[i] == '2') {
        small = small + '1';
        big = big + '1';
      } else {
        ind = i;
        big = big + '1';
        small = small + '0';
        break;
      }
    }
    if (ind != -1) {
      for (int i = ind + 1; i < n; i++) {
        if (q[i] == '2') {
          big = big + '0';
          small = small + '2';
        } else if (q[i] == '0') {
          small = small + '0';
          big = big + '0';
        } else {
          big = big + '0';
          small = small + '1';
        }
      }
    }
    cout << big << "\n";
    cout << small << "\n";
  }
}
