# Chess Tournament solution codeforces – A chess tournament will be held soon, where nn chess players will take part. Every participant will play one game against every other participant.

## Chess Tournament solution codeforces

A chess tournament will be held soon, where nn 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 tt (1t2001≤t≤200) — the number of test cases.

The first line of each test case contains one integer nn (2n502≤n≤50) — the number of chess players.

The second line contains the string ss (|s|=n|s|=nsi{1,2}si∈{1,2}). If si=1si=1, then the ii-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×nn×n in the next nn lines.

The matrix element in the ii-th row and jj-th column should be equal to:

• +, if the ii-th player won in a game against the jj-th player;
• , if the ii-th player lost in a game against the jj-th player;
• =, if the ii-th and jj-th players’ game resulted in a draw;
• X, if i=ji=j.
Example

input

Copy
3
3
111
2
21
4
2122


output

Copy
YES
X==
=X=
==X
NO
YES
X--+
+X++
+-X-
--+X


## Solution

#include<bits/stdc++.h>
using namespace std;

#define fl float

#define dl double long

#define F first

#define ll long long int

#define lo(x,start,end) for(int x=start;x<end;++x)

#define S second

#define pb push_back

#define eif else if

#define eb emplace_back

int32_t main() {

int tc;

cin>>tc;

while (tc–)

{

long long n;

cin >> n ;

string s;

cin >> s ;

vector<long long>ppr;

char array[n+10][n+10];

long long Count_2 = 0;

for(int i=0;i<n;i++) {

Count_2+=(s[i]==‘2’);

if(s[i]==‘2’) {

ppr.push_back(i);

}

}

memset(array,‘.’,sizeof array);

if(Count_2<=2 && Count_2) {

cout << “NO\n”;

}

else {

cout << “YES\n”;

for(int i=0;i<s.size();i++) {

if(s[i]==‘1’) {

for(int j=0;j<n;j++) {

array[i][j]=‘=’;

array[j][i]=‘=’;

}

}

}

for(int i=0;i<ppr.size();i++) {

for(int j=0;j<ppr.size();j++) {

if(i==j){continue;}

if(array[ppr[i]][ppr[j]]==‘.’) {

array[ppr[i]][ppr[j]] =‘=’;

array[ppr[i]][ppr[j]] = ‘=’;

}

}

if(i==ppr.size()-1) {

array[ppr[i]][ppr[0]]=‘+’;

array[ppr[0]][ppr[i]]=‘-‘;

}

else{

array[ppr[i]][ppr[i+1]]=‘+’;

array[ppr[i+1]][ppr[i]]=‘-‘;

}

}

for(int i=0;i<n;i++) {

array[i][i]=‘X’;

for(int j=0;j<n;j++) {

cout <<array[i][j];

}

cout << ‘\n’;

}

}

}

return 0;
}

Also read : Chess Tournament solution codeforces