description: n players are playing a game. 
  
  There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. 
  
  You are the game master and want to organize a tournament. There will be a total of n-1 battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. 
  
  In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The description of test cases follows.
  
  The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of players.
  
  The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9, a_i ≠ a_j for i ≠ j), where a_i is the strength of the i-th player on the first map. 
  
  The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ 10^9, b_i ≠ b_j for i ≠ j), where b_i is the strength of the i-th player on the second map. 
  
  It is guaranteed that the sum of n over all test cases does not exceed 10^5.
  
  Output
  
  For each test case print a string of length n. i-th character should be "1" if the i-th player can win the tournament, or "0" otherwise.
  
  Example
  
  Input
  
  
  3
  4
  1 2 3 4
  1 2 3 4
  4
  11 12 20 21
  44 22 11 30
  1
  1000000000
  1000000000
  
  
  Output
  
  
  0001
  1111
  1
  
  Note
  
  In the first test case, the 4-th player will beat any other player on any game, so he will definitely win the tournament.
  
  In the second test case, everyone can be a winner. 
  
  In the third test case, there is only one player. Clearly, he will win the tournament.
solution: // package c1608;
  
  import java.io.File;
  import java.lang.invoke.MethodHandles;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.List;
  import java.util.PriorityQueue;
  import java.util.Random;
  import java.util.Scanner;
  
  //
  // Codeforces Round 2021-12-11 02:05
  // C. Game Master
  // https://codeforces.com/contest/1608/problem/C
  // time limit per test 1 second; memory limit per test 256 megabytes
  // public class Pseudo for 'Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).*'
  //
  // n players are playing a game.
  //
  // There are two different maps in the game. For each player, we know his strength on each map. When
  // two players fight on a specific map, the player with higher strength on that map always wins. No
  // two players have the same strength on the same map.
  //
  // You are the game master and want to organize a tournament. There will be a total of n-1 battles.
  // While there is more than one player in the tournament, choose any map and any two remaining
  // players to fight on it. The player who loses will be eliminated from the tournament.
  //
  // In the end, exactly one player will remain, and he is declared the winner of the tournament. For
  // each player determine if he can win the tournament.
  //
  // Input
  //
  // The first line contains a single integer t (1 <= t <= 100) -- the number of test cases. The
  // description of test cases follows.
  //
  // The first line of each test case contains a single integer n (1 <=q n <=q 10^5) -- the number of
  // players.
  //
  // The second line of each test case contains n integers a_1, a_2, ..., a_n (1 <=q a_i <=q 10^9, a_i
  // \neq a_j for i \neq j), where a_i is the strength of the i-th player on the first map.
  //
  // The third line of each test case contains n integers b_1, b_2, ..., b_n (1 <=q b_i <=q 10^9, b_i
  // \neq b_j for i \neq j), where b_i is the strength of the i-th player on the second map.
  //
  // It is guaranteed that the sum of n over all test cases does not exceed 10^5.
  //
  // Output
  //
  // For each test case print a string of length n. i-th character should be "" if the i-th player can
  // win the tournament, or "" otherwise.
  //
  // Example
  /*
  input:
  3
  4
  1 2 3 4
  1 2 3 4
  4
  11 12 20 21
  44 22 11 30
  1
  1000000000
  1000000000
  
  output:
  0001
  1111
  1
  */
  // Note
  //
  // In the first test case, the 4-th player will beat any other player on any game, so he will
  // definitely win the tournament.
  //
  // In the second test case, everyone can be a winner.
  //
  // In the third test case, there is only one player. Clearly, he will win the tournament.
  //
  public class C1608C {
    static final int MOD = (int)1e9+7;
    static final Random RAND = new Random();
  
    static class TestCase {
      int n;
      // Both id and rank are in the range [0,n-1). Rank n-1 has the highest strength.
      // ra[i] is the rank of id i in a
      int[] ra;
      int[] rb;
  
      // ia[i] is the id of rank i in map a (reverse lookup of ra)
      int[] ia;
      int[] ib;
  
      TestCase(int[] a, int[] b) {
        init(a, b);
      }
  
      void init(int[] a, int[] b) {
        this.n = a.length;
        this.ra = getRankArray(a);
        this.rb = getRankArray(b);
        this.ia = new int[n];
        this.ib = new int[n];
        for (int i = 0; i < n; i++) {
          ia[ra[i]] = i;
          ib[rb[i]] = i;
        }
      }
  
      static void handle(int[] ia, int[] ib, int[] ra, int[] rb, boolean[] oks) {
        // Consider players in increasing order of rank in map a.
        //
        // In below, A eliminates C in mapb, B eliminates A in map A
        //           A   B   C
        //  map a:   *   *   *
        //            \ /   /
        //             X   /
        //            / \ /
        //           /   X
        //          /   / \
        //  map b: * o *   *
        //
        // We like to find the minimal rank in map b of the final survivor across all
        // superior players in map a.
        //
        int n = ia.length;
        int max = 0;
        PriorityQueue<Integer> pq = new PriorityQueue<>((x,y)->rb[y] - rb[x]);
        int[] suf = new int[n];
        suf[n-1] = rb[ia[n-1]];
        pq.add(ia[n-1]);
        for (int r = n - 2; r >= 0; r--) {
          int id = ia[r];
          int x = rb[id];
          if (x < rb[pq.peek()]) {
            pq.add(id);
          } else {
            while (pq.size() > 1 && x > rb[pq.peek()]) {
              pq.poll();
            }
          }
          suf[r] = rb[pq.peek()];
        }
        for (int r = 0; r < n; r++) {
          int id = ia[r];
          max = Math.max(max, rb[id]);
          // System.out.format("  r:%d id:%d suf:%d\n", r, id, suf[r]);
          if (max >= suf[r]) {
            oks[id] = true;
          }
        }
      }
  
      String solve() {
        boolean[] oks = new boolean[n];
        handle(ia, ib, ra, rb, oks);
        handle(ib, ia, rb, ra, oks);
  
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
          sb.append(oks[i] ? 1 : 0);
        }
        return sb.toString();
      }
  
      // Gets rank array where rank[i] is the rank (0-based) of a[i] in a
      static int[] getRankArray(int[] a) {
        int n = a.length;
        int[][] x = new int[n][2];
        for (int i = 0; i < n; i++) {
          x[i][0] = a[i];
          x[i][1] = i;
        }
        Arrays.sort(x, (v, w)->Integer.compare(v[0], w[0]));
        int[] ra = new int[n];
        for (int i = 0; i < n; i++) {
          ra[x[i][1]] = i;
        }
        return ra;
      }
    }
  
    static void doTest() {
      int n = 10;
      List<Integer> arr = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        arr.add(i);
      }
      Collections.shuffle(arr);
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = arr.get(i);
      }
      Collections.shuffle(arr);
      int[] b = new int[n];
      for (int i = 0; i < n; i++) {
        b[i] = arr.get(i);
      }
      System.out.format("  a:%s\n", Arrays.toString(a));
      System.out.format("  b:%s\n", Arrays.toString(b));
      TestCase tc = new TestCase(a,b);
      String ans = tc.solve();
      System.out.println(ans);
      System.exit(0);
    }
  
    public static void main(String[] args) {
      // doTest();
      Scanner in = getInputScanner();
      int T = in.nextInt();
      for (int t = 1; t <= T; t++) {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
          a[i] = in.nextInt();
        }
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
          b[i] = in.nextInt();
        }
        TestCase tc = new TestCase(a,b);
        String ans = tc.solve();
        System.out.println(ans);
      }
      in.close();
    }
  
    static Scanner getInputScanner() {
      try {
        final String USERDIR = System.getProperty("user.dir");
        final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();
        final File fin = new File(USERDIR + "/io/c" + CNAME.substring(1,5) + "/" + CNAME + ".in");
        return fin.exists() ? new Scanner(fin) : new Scanner(System.in);
      } catch (Exception e) {
        return new Scanner(System.in);
      }
    }
  }
  