def lastIndex(arr, x):
for i in reversed(range(len(arr))):
if(arr[i] == x):
return i
def solve(n, exp):
if exp.count(2) in range(1,3):
print('NO')
return
else:
board = [['=' for i in range(n)]for i in range(n)]
for i in range(n):
board[i][i] = 'X'
if exp.count(2) != 0:
firstIndexOf2 = exp.index(2)
lastIndexOf2 = lastIndex(exp, 2)
for i in range(firstIndexOf2, lastIndexOf2):
if(exp[i] == 2):
for j in range(i+1, lastIndexOf2 + 1):
if(exp[j] == 2):
board[i][j] = '+'
board[j][i] = '-'
board[lastIndexOf2][firstIndexOf2] = '+'
board[firstIndexOf2][lastIndexOf2] = '-'
print('YES')
for i in range(n):
print(''.join(board[i]))
tcs = int(input())
for i in range(tcs):
n = int(input())
e = input()
exp = list(map(int, e))
solve(n, exp)
/*
** Author - Md. Najmul Huda Hridoy
** Handle - h3000plus
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int two = 0;
vector<int> idx;
vector<vector<char>> ans(n, vector<char>(n));
for(int i = 0; i < n; i++){
if(s[i] == '2'){
two++;
idx.push_back(i);
}
}
if(two == 1 || two == 2){
cout<<"NO"<<endl;
}
else{
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j) ans[i][j] = 'X';
else ans[i][j] = '=';
}
}
if(two > 2){
int sz = idx.size() - 1;
ans[idx[0]][idx[sz]] = '+';
ans[idx[sz]][idx[0]] = '-';
ans[idx[sz]][idx[sz - 1]] = '+';
ans[idx[sz - 1]][idx[sz]] = '-';
for(int i = 1; i < sz; i++){
ans[idx[i]][idx[i - 1]] = '+';
ans[idx[i - 1]][idx[i]] = '-';
}
}
cout<<"YES"<<endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout<<ans[i][j];
}
cout<<endl;
}
}
}
return 0;
}
144. Binary Tree Preorder Traversal | 137. Single Number II |
130. Surrounded Regions | 129. Sum Root to Leaf Numbers |
120. Triangle | 102. Binary Tree Level Order Traversal |
96. Unique Binary Search Trees | 75. Sort Colors |
74. Search a 2D Matrix | 71. Simplify Path |
62. Unique Paths | 50. Pow(x, n) |
43. Multiply Strings | 34. Find First and Last Position of Element in Sorted Array |
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |