#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<algorithm>
#include<iostream>
#include<hash_map>
#include<iterator>
#include<iomanip>
#include<numeric>
#include<cstring>
#include<vector>
#include<bitset>
#include<string>
#include<deque>
#include<stack>
#include<queue>
#include<array>
#include<cmath>
#include<list>
#include<map>
#include<set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
#define ordered_set tree<ll, null_type,less_equal<ll>, \
rb_tree_tag,tree_order_statistics_node_update>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf INT32_MAX
#define linf INT64_MAX
#define pf push_front
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
ll fastPow(ll n, ll k/*,ll m*/) {
if (k == 0)return 1;
ll res = fastPow(n, k / 2/*,m*/)/*%m*/;
res = (res * res)/*%m*/;
if (k & 1)res = (res * n)/*%m*/;
return res/*%m*/;
}
ll fastPow(ll n, ll k, ll m) {
if (k == 0)return 1;
ll res = fastPow(n, k / 2, m) % m;
res = (res * res) % m;
if (k & 1)res = (res * n) % m;
return res % m;
}
ll calcMod(ll a, ll m) {
return (a % m + m) % m;
}
ll Ceil(ll n, ll m) {
return (n + m - 1) / m;
}
const ll mod = 1e9 + 7;
bool solve() {
int n;
cin >> n;
vector<pii > v(n), a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> v[i].ff;
a[i] = {v[i].ff, i};
}
for (int i = 0; i < n; ++i) {
cin >> v[i].ss;
b[i] = {v[i].ss, i};
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
string ans(n, '0');
int startA;
for (int i = n - 1; i >= 0; --i) {
if (v[a[i].ss].ss >= v[a[n - 1].ss].ss) {
startA = i;
}
}
for (int i = startA; i < n; ++i) {
ans[a[i].ss] = '1';
}
int startB;
for (int i = n - 1; i >= 0; --i) {
if (v[b[i].ss].ff >= v[b[n - 1].ss].ff) {
startB = i;
}
}
for (int i = startB; i < n; ++i) {
ans[b[i].ss] = '1';
}
cout << ans << "\n";
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
I2luY2x1ZGU8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGU8dW5vcmRlcmVkX3NldD4KI2luY2x1ZGU8ZnVuY3Rpb25hbD4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8aGFzaF9tYXA+CiNpbmNsdWRlPGl0ZXJhdG9yPgojaW5jbHVkZTxpb21hbmlwPgojaW5jbHVkZTxudW1lcmljPgojaW5jbHVkZTxjc3RyaW5nPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPGJpdHNldD4KI2luY2x1ZGU8c3RyaW5nPgojaW5jbHVkZTxkZXF1ZT4KI2luY2x1ZGU8c3RhY2s+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxhcnJheT4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPGxpc3Q+CiNpbmNsdWRlPG1hcD4KI2luY2x1ZGU8c2V0PgoKI2luY2x1ZGUgPGV4dC9wYl9kcy9hc3NvY19jb250YWluZXIuaHBwPgojaW5jbHVkZSA8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KCnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgdW5zaWduZWQgbG9uZyBsb25nIHVsbDsKdHlwZWRlZiBkb3VibGUgZGI7CnR5cGVkZWYgbG9uZyBkb3VibGUgbGRiOwoKI2RlZmluZSBvcmRlcmVkX3NldCB0cmVlPGxsLCBudWxsX3R5cGUsbGVzc19lcXVhbDxsbD4sIFwKcmJfdHJlZV90YWcsdHJlZV9vcmR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ihuKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgY2luID4+IHZbaV0uZmY7CiAgICAgICAgYVtpXSA9IHt2W2ldLmZmLCBpfTsKICAgIH0KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgY2luID4+IHZbaV0uc3M7CiAgICAgICAgYltpXSA9IHt2W2ldLnNzLCBpfTsKICAgIH0KICAgIHNvcnQoYS5iZWdpbigpLCBhLmVuZCgpKTsKICAgIHNvcnQoYi5iZWdpbigpLCBiLmVuZCgpKTsKCiAgICBzdHJpbmcgYW5zKG4sICcwJyk7CiAgICBpbnQgc3RhcnRBOwogICAgZm9yIChpbnQgaSA9IG4gLSAxOyBpID49IDA7IC0taSkgewogICAgICAgIGlmICh2W2FbaV0uc3NdLnNzID49IHZbYVtuIC0gMV0uc3NdLnNzKSB7CiAgICAgICAgICAgIHN0YXJ0QSA9IGk7CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IHN0YXJ0QTsgaSA8IG47ICsraSkgewogICAgICAgIGFuc1thW2ldLnNzXSA9ICcxJzsKICAgIH0KCiAgICBpbnQgc3RhcnRCOwogICAgZm9yIChpbnQgaSA9IG4gLSAxOyBpID49IDA7IC0taSkgewogICAgICAgIGlmICh2W2JbaV0uc3NdLmZmID49IHZbYltuIC0gMV0uc3NdLmZmKSB7CiAgICAgICAgICAgIHN0YXJ0QiA9IGk7CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IHN0YXJ0QjsgaSA8IG47ICsraSkgewogICAgICAgIGFuc1tiW2ldLnNzXSA9ICcxJzsKICAgIH0KCiAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgcmV0dXJuIDE7Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwoKICAgIGludCB0ID0gMTsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkgewogICAgICAgIHNvbHZlKCk7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=