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: import java.io.*;
  import java.util.*;
  
  public class GameMaster {
  
      static int p;
      static boolean map1on;
  
      public static void main(String[] args) throws Exception {
  
          CustomScanner sc = new CustomScanner();
          CustomPrinter cp = new CustomPrinter();
          int T = sc.nextInt();
          for (int t =0; t < T; t++){
              p = sc.nextInt();
              int[] m1 = sc.nextIntArray(p);
              int[] m2 = sc.nextIntArray(p);
              int i;
              Player[] players = new Player[p];
              StringBuilder sb = new StringBuilder(p);
              for (i=0;i<p;i++){
                  players[i] = new Player(m1[i],m2[i]);
              }
              Player[] map1 = players.clone();
              Player[] map2 = players.clone();
              map1on = true;
              Arrays.sort(map1);
  
              map1on = false;
              Arrays.sort(map2);
  
  
              int pointofmax1 = map1[0].map2;
              int pointofmax2 = map2[0].map1;
  
              //logic is : if you can beat the guy who can beat the highest dude in map A in map B, you can win the tournament;
              //vice-versa for map b.
              boolean notdone = true;
              int k=0;
              while(notdone && k < players.length) {
                  notdone = false;
                  Player player1 = map1[k];
                  Player player2 = map2[k];
                  if (player1.map2 >= pointofmax1 || player1.map1 >= pointofmax2) {
                      player1.possible = true;
                      pointofmax1 = Math.min(pointofmax1, player1.map2);
                      pointofmax2 = Math.min(pointofmax2, player1.map1);
                      notdone = true;
                  }
  
                  if (player2.map2 >= pointofmax1 || player2.map1 >= pointofmax2) {
                      player2.possible = true;
                      pointofmax1 = Math.min(pointofmax1, player2.map2);
                      pointofmax2 = Math.min(pointofmax2, player2.map1);
                      notdone = true;
                  }
                  k++;
              }
  
  
              for (Player player : players){
                  if (player.possible){
                      sb.append('1');
                  }else{
                      sb.append('0');
                  }
              }
              cp.print(sb);
              cp.print("\n");
  
          }
          cp.close();
      }
  
      public static class Player implements Comparable<Player>{
  
          int map1;
          int map2;
          boolean possible;
  
          Player(int a, int b){
              this.map1 = a;
              this.map2 = b;
          }
  
  
          @Override
          public int compareTo(Player p) {
              if(map1on){
                  return this.map1 > p.map1 ? -1 : 1;
              }else{
                  return this.map2 > p.map2 ? -1 : 1;
              }
          }
  
          @Override
          public String toString() {
              return "Player{" +
                      "map1=" + map1 +
                      ", map2=" + map2 +
                      ", possible=" + possible +
                      '}';
          }
      }
  
      static class CustomScanner {
          private final InputStream in;
          private final byte[] buffer = new byte[1024];
          private int ptr = 0;
          private int buflen = 0;
  
          private static final long LONG_MAX_TENTHS = 922337203685477580L;
          private static final int LONG_MAX_LAST_DIGIT = 7;
          private static final int LONG_MIN_LAST_DIGIT = 8;
  
          public CustomScanner(InputStream in) {
              this.in = in;
          }
  
          public CustomScanner() {
              this(System.in);
          }
  
          private boolean hasNextByte() {
              if (ptr < buflen) {
                  return true;
              } else {
                  ptr = 0;
                  try {
                      buflen = in.read(buffer);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
                  if (buflen <= 0) {
                      return false;
                  }
              }
              return true;
          }
  
          private int readByte() {
              if (hasNextByte())
                  return buffer[ptr++];
              else
                  return -1;
          }
  
          private static boolean isPrintableChar(int c) {
              return 33 <= c && c <= 126;
          }
  
          public boolean hasNext() {
              while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                  ptr++;
              return hasNextByte();
          }
  
          public String next() {
              if (!hasNext())
                  throw new NoSuchElementException();
              StringBuilder sb = new StringBuilder();
              int b = readByte();
              while (isPrintableChar(b)) {
                  sb.appendCodePoint(b);
                  b = readByte();
              }
              return sb.toString();
          }
  
          public long nextLong() {
              if (!hasNext())
                  throw new NoSuchElementException();
              long n = 0;
              boolean minus = false;
              int b = readByte();
              if (b == '-') {
                  minus = true;
                  b = readByte();
              }
              if (b < '0' || '9' < b) {
                  throw new NumberFormatException();
              }
              while (true) {
                  if ('0' <= b && b <= '9') {
                      int digit = b - '0';
                      if (n >= LONG_MAX_TENTHS) {
                          if (n == LONG_MAX_TENTHS) {
                              if (minus) {
                                  if (digit <= LONG_MIN_LAST_DIGIT) {
                                      n = -n * 10 - digit;
                                      b = readByte();
                                      if (!isPrintableChar(b)) {
                                          return n;
                                      } else if (b < '0' || '9' < b) {
                                          throw new NumberFormatException(
                                                  String.format("%d%s... is not number", n, Character.toString(b)));
                                      }
                                  }
                              } else {
                                  if (digit <= LONG_MAX_LAST_DIGIT) {
                                      n = n * 10 + digit;
                                      b = readByte();
                                      if (!isPrintableChar(b)) {
                                          return n;
                                      } else if (b < '0' || '9' < b) {
                                          throw new NumberFormatException(
                                                  String.format("%d%s... is not number", n, Character.toString(b)));
                                      }
                                  }
                              }
                          }
                          throw new ArithmeticException(
                                  String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit));
                      }
                      n = n * 10 + digit;
                  } else if (b == -1 || !isPrintableChar(b)) {
                      return minus ? -n : n;
                  } else {
                      throw new NumberFormatException();
                  }
                  b = readByte();
              }
          }
  
          public int nextInt() {
              long nl = nextLong();
              if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                  throw new NumberFormatException();
              return (int) nl;
          }
  
          public double nextDouble() {
              return Double.parseDouble(next());
          }
  
          public long[] nextLongArray(int length) {
              long[] array = new long[length];
              for (int i = 0; i < length; i++)
                  array[i] = this.nextLong();
              return array;
          }
  
          public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) {
              long[] array = new long[length];
              for (int i = 0; i < length; i++)
                  array[i] = map.applyAsLong(this.nextLong());
              return array;
          }
  
          public int[] nextIntArray(int length) {
              int[] array = new int[length];
              for (int i = 0; i < length; i++)
                  array[i] = this.nextInt();
              return array;
          }
  
          public int[][] nextIntArrayMulti(int length, int width) {
              int[][] arrays = new int[width][length];
              for (int i = 0; i < length; i++) {
                  for (int j = 0; j < width; j++)
                      arrays[j][i] = this.nextInt();
              }
              return arrays;
          }
  
          public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) {
              int[] array = new int[length];
              for (int i = 0; i < length; i++)
                  array[i] = map.applyAsInt(this.nextInt());
              return array;
          }
  
          public double[] nextDoubleArray(int length) {
              double[] array = new double[length];
              for (int i = 0; i < length; i++)
                  array[i] = this.nextDouble();
              return array;
          }
  
          public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) {
              double[] array = new double[length];
              for (int i = 0; i < length; i++)
                  array[i] = map.applyAsDouble(this.nextDouble());
              return array;
          }
  
          public long[][] nextLongMatrix(int height, int width) {
              long[][] mat = new long[height][width];
              for (int h = 0; h < height; h++)
                  for (int w = 0; w < width; w++) {
                      mat[h][w] = this.nextLong();
                  }
              return mat;
          }
  
          public int[][] nextIntMatrix(int height, int width) {
              int[][] mat = new int[height][width];
              for (int h = 0; h < height; h++)
                  for (int w = 0; w < width; w++) {
                      mat[h][w] = this.nextInt();
                  }
              return mat;
          }
  
          public double[][] nextDoubleMatrix(int height, int width) {
              double[][] mat = new double[height][width];
              for (int h = 0; h < height; h++)
                  for (int w = 0; w < width; w++) {
                      mat[h][w] = this.nextDouble();
                  }
              return mat;
          }
  
          public char[][] nextCharMatrix(int height, int width) {
              char[][] mat = new char[height][width];
              for (int h = 0; h < height; h++) {
                  String s = this.next();
                  for (int w = 0; w < width; w++) {
                      mat[h][w] = s.charAt(w);
                  }
              }
              return mat;
          }
      }
  
      static class CustomPrinter extends PrintWriter {
          public CustomPrinter(PrintStream stream) {
              super(stream);
          }
  
          public CustomPrinter() {
              super(System.out);
          }
  
          private static String dtos(double x, int n) {
              StringBuilder sb = new StringBuilder();
              if (x < 0) {
                  sb.append('-');
                  x = -x;
              }
              x += Math.pow(10, -n) / 2;
              sb.append((long) x);
              sb.append(".");
              x -= (long) x;
              for (int i = 0; i < n; i++) {
                  x *= 10;
                  sb.append((int) x);
                  x -= (int) x;
              }
              return sb.toString();
          }
  
          @Override
          public void print(float f) {
              super.print(dtos(f, 20));
          }
  
          @Override
          public void println(float f) {
              super.println(dtos(f, 20));
          }
  
          @Override
          public void print(double d) {
              super.print(dtos(d, 20));
          }
  
          @Override
          public void println(double d) {
              super.println(dtos(d, 20));
          }
  
          public void printArray(int[] array, String separator) {
              int n = array.length;
              for (int i = 0; i < n - 1; i++) {
                  super.print(array[i]);
                  super.print(separator);
              }
              super.println(array[n - 1]);
          }
  
          public void printArray(int[] array) {
              this.printArray(array, " ");
          }
  
          public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) {
              int n = array.length;
              for (int i = 0; i < n - 1; i++) {
                  super.print(map.applyAsInt(array[i]));
                  super.print(separator);
              }
              super.println(map.applyAsInt(array[n - 1]));
          }
  
          public void printArray(int[] array, java.util.function.IntUnaryOperator map) {
              this.printArray(array, " ", map);
          }
  
          public void printArray(long[] array, String separator) {
              int n = array.length;
              for (int i = 0; i < n - 1; i++) {
                  super.print(array[i]);
                  super.print(separator);
              }
              super.println(array[n - 1]);
          }
  
          public void printArray(long[] array) {
              this.printArray(array, " ");
          }
  
          public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) {
              int n = array.length;
              for (int i = 0; i < n - 1; i++) {
                  super.print(map.applyAsLong(array[i]));
                  super.print(separator);
              }
              super.println(map.applyAsLong(array[n - 1]));
          }
  
          public void printArray(long[] array, java.util.function.LongUnaryOperator map) {
              this.printArray(array, " ", map);
          }
  
      }
  
      public static void safeSort(int[] array) {
          Integer[] temp = new Integer[array.length];
          for (int n = 0; n < array.length; n++) {
              temp[n] = array[n];
          }
          Arrays.sort(temp);
          for (int n = 0; n < array.length; n++) {
              array[n] = temp[n];
          }
      }
  
      public static void safeSort(long[] array) {
          Long[] temp = new Long[array.length];
          for (int n = 0; n < array.length; n++) {
              temp[n] = array[n];
          }
          Arrays.sort(temp);
          for (int n = 0; n < array.length; n++) {
              array[n] = temp[n];
          }
      }
  
      public static void safeSort(double[] array) {
          Double[] temp = new Double[array.length];
          for (int n = 0; n < array.length; n++) {
              temp[n] = array[n];
          }
          Arrays.sort(temp);
          for (int n = 0; n < array.length; n++) {
              array[n] = temp[n];
          }
      }
  
  }