#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define inf LLONG_MAX
#define ti tuple<int,int,int>
const int lim=1000;
int grid[lim+100][lim+100];
int a[lim+100][lim+100];
int b[lim+100][lim+100];
int fg(int n,int m,int num){
memset(grid,0,sizeof(grid));
//awal dari cycle tsb
int cnt=0;
int rm=m/2+1;
//red sampe kemana
int maks=(n-1)/2;
//ngisi berapa row
int i=1;
while(cnt<maks){
for(int j=1;j<=rm;j++) grid[i][j]++;
i++;
if(i>n) break;
for(int j=rm+1;j<=m;j++) grid[i][j]++;
cnt++;
i++;
}
int ans=0;
for(int i=1;i<=n;i++){
int cur=0;
for(int j=1;j<=m;j++) if(grid[i][j]) cur++;
if(cur>=rm)ans++;
}
for(int i=1;i<=m;i++){
int cur=0;
for(int j=1;j<=n;j++) if(!grid[j][i]) cur++;
if(cur>=n/2+1)ans++;
}
if(num==1){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[i][j]=grid[i][j];
// cout<<a[i][j];
}
// cout<<endl;
}
}
else{
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
b[i][j]=grid[i][j];
}
}
}
return ans;
}
signed main(){
int t;cin>>t;while(t--){
int n,m;cin>>n>>m;
int aa=fg(n,m,1);
int bb=fg(m,n,2);
if(aa>bb){
cout<<aa<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]) cout<<'+';
else cout<<'-';
}
cout<<endl;
}
}
else{
cout<<bb<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[j][i]) cout<<'-';
else cout<<'+';
}
cout<<endl;
}
}
//all blue
// cout<<ans<<endl;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++){
// if(grid[i][j]) cout<<'-';
// else cout<<'+';
// }
// cout<<endl;
// }
// cout<<endl;
}
}
// Row red>blue
// Col red<blue
// val less than half
// val more than half
// +--+
// +--+
// ++++
// -++
// ---
// ---
// ---
// +++-
// ----
// ----
// +-++
// +-++
// ++
// ++
// ++
// ++
// +++
// +++
// +++
// case
// 1. odd m -> bisa dibagi 2
// kiri
// (m+1)/2
// (n+1)/2 -1 times
// kanan
// (m+1)/2+1
// (n+1)/2 -1 times
// 2. even m
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |