description: A chess tournament will be held soon, where n chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.
  
  Each of the players has their own expectations about the tournament, they can be one of two types:
  
    1. a player wants not to lose any game (i. e. finish the tournament with zero losses); 
    2. a player wants to win at least one game. 
  
  
  
  You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it's impossible.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 200) — the number of test cases.
  
  The first line of each test case contains one integer n (2 ≤ n ≤ 50) — the number of chess players.
  
  The second line contains the string s (|s| = n; s_i ∈ \{1, 2\}). If s_i = 1, then the i-th player has expectations of the first type, otherwise of the second type.
  
  Output
  
  For each test case, print the answer in the following format:
  
  In the first line, print NO if it is impossible to meet the expectations of all players.
  
  Otherwise, print YES, and the matrix of size n × n in the next n lines.
  
  The matrix element in the i-th row and j-th column should be equal to:
  
    * +, if the i-th player won in a game against the j-th player; 
    * -, if the i-th player lost in a game against the j-th player; 
    * =, if the i-th and j-th players' game resulted in a draw; 
    * X, if i = j. 
  
  Example
  
  Input
  
  
  3
  3
  111
  2
  21
  4
  2122
  
  
  Output
  
  
  YES
  X==
  =X=
  ==X
  NO
  YES
  X--+
  +X++
  +-X-
  --+X
solution: 
  import java.io.*;
  import java.util.*;
  
  public class ChessTournament implements Runnable {
  
     void solve() {
        int t = ri();
        outer: while (t-- > 0) {
           int players = ri();
           String s = rs();
           List<Integer> twos = new ArrayList<>();
           for (int i = 0; i < s.length(); i++) {
              if (s.charAt(i) == '2')
                 twos.add(i);
           }
           if (twos.size() == 1 || twos.size() == 2) {
              println("NO");
              continue outer;
           }
           println("YES");
           char[][] ans = new char[players][players];
           for (char[] a : ans)
              Arrays.fill(a, '=');
           for (int i = 0; i < s.length(); i++) {
              ans[i][i] = 'X';
           }
  
           // player can win againt next player ( mod )
           for (int i = 0; i < twos.size(); i++) {
              int curr = twos.get(i), next = twos.get((i + 1) % twos.size());
              ans[curr][next] = '+';
              ans[next][curr] = '-';
           }
           for (int i = 0; i < ans.length; i++) {
              for (int j = 0; j < ans[0].length; j++) {
                 print(ans[i][j]);
              }
              println("");
           }
        }
     }
  
     /************************************************************************************************************************************************/
     public static void main(String[] args) throws IOException {
        new Thread(null, new ChessTournament(), "1").start();
     }
  
     static PrintWriter out = new PrintWriter(System.out);
     static Reader read = new Reader();
     static StringBuilder sbr = new StringBuilder();
     static int mod = (int) 1e9 + 7;
     static int dmax = Integer.MAX_VALUE;
     static long lmax = Long.MAX_VALUE;
     static int dmin = Integer.MIN_VALUE;
     static long lmin = Long.MIN_VALUE;
     static int[] dprimes = new int[] { 1, 11, 101, 1087, 99991, 100001, 1000003, 15485863, 999999937 };
  
     @Override
     public void run() {
        solve();
        out.close();
     }
  
     static class Reader {
        private byte[] buf = new byte[1024];
        private int index;
        private InputStream in;
        private int total;
  
        public Reader() {
           in = System.in;
        }
  
        public int scan() throws IOException {
           if (total < 0)
              throw new InputMismatchException();
           if (index >= total) {
              index = 0;
              total = in.read(buf);
              if (total <= 0)
                 return -1;
           }
           return buf[index++];
        }
  
        public int intNext() throws IOException {
           int integer = 0;
           int n = scan();
           while (isWhiteSpace(n))
              n = scan();
           int neg = 1;
           if (n == '-') {
              neg = -1;
              n = scan();
           }
           while (!isWhiteSpace(n)) {
              if (n >= '0' && n <= '9') {
                 integer *= 10;
                 integer += n - '0';
                 n = scan();
              } else
                 throw new InputMismatchException();
           }
           return neg * integer;
        }
  
        public double doubleNext() throws IOException {
           double doub = 0;
           int n = scan();
           while (isWhiteSpace(n))
              n = scan();
           int neg = 1;
           if (n == '-') {
              neg = -1;
              n = scan();
           }
           while (!isWhiteSpace(n) && n != '.') {
              if (n >= '0' && n <= '9') {
                 doub *= 10;
                 doub += n - '0';
                 n = scan();
              } else
                 throw new InputMismatchException();
           }
           if (n == '.') {
              n = scan();
              double temp = 1;
              while (!isWhiteSpace(n)) {
                 if (n >= '0' && n <= '9') {
                    temp /= 10;
                    doub += (n - '0') * temp;
                    n = scan();
                 } else
                    throw new InputMismatchException();
              }
           }
           return doub * neg;
        }
  
        public String read() throws IOException {
           StringBuilder sb = new StringBuilder();
           int n = scan();
           while (isWhiteSpace(n))
              n = scan();
           while (!isWhiteSpace(n)) {
              sb.append((char) n);
              n = scan();
           }
           return sb.toString();
        }
  
        public String rline() throws IOException {
           StringBuilder sb = new StringBuilder();
           int n = scan();
           while (n != '\n') {
              sb.append((char) n);
              n = scan();
           }
           return sb.toString();
        }
  
        private boolean isWhiteSpace(int n) {
           if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
              return true;
           return false;
        }
     }
  
     static void print(Object object) {
        out.print(object);
     }
  
     static void println(Object object) {
        out.println(object);
     }
  
     static int[] iArr(int len) {
        return new int[len];
     }
  
     static long[] lArr(int len) {
        return new long[len];
     }
  
     static long min(long a, long b) {
        return Math.min(a, b);
     }
  
     static int min(int a, int b) {
        return Math.min(a, b);
     }
  
     static long max(Long a, Long b) {
        return Math.max(a, b);
     }
  
     static int max(int a, int b) {
        return Math.max(a, b);
     }
  
     static int ri() {
        try {
           return read.intNext();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return -1;
     }
  
     static long rl() {
        try {
           return Long.parseLong(read.read());
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return -1;
     }
  
     static String rs() {
        try {
           return read.read();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return "";
     }
  
     static String rline() {
        try {
           return read.rline();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return "";
     }
  
     static char rc() {
        return rs().charAt(0);
     }
  
     static double rd() {
        try {
           return read.doubleNext();
        } catch (IOException e) {
           e.printStackTrace();
        }
        System.exit(2);
        return -1;
     }
  }
  