#include <bits/stdc++.h>
using namespace std;
#define MAXN 1001
#define int long long
int t,n,m;
char a[2][MAXN][MAXN];
vector<int> columns[MAXN];
vector<int> rows[MAXN];
int32_t main()
{
cin>>t;
for (int test=0;test<t;test++)
{
cin>>n>>m;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++)
{
a[0][row][col]='+';
a[1][row][col]='-';
}
}
for (int row=1;row<=n;row++)
{
int starting=(row-1)%m+1,ending=(row-1)%m+1+m/2-1;
for (int col=starting;col<=min(m,ending);col++) a[0][row][col]='-';
for (int col=1;col+m<=ending;col++) a[0][row][col]='-';
}
for (int col=1;col<=m;col++)
{
int number=0;
for (int row=1;row<=n;row++)
{
if (a[0][row][col]=='-') number++;
}
columns[number].push_back(col);
}
int target=n/2,curr=1;
while (curr<=n and target>=0)
{
int possible=0;
for (int col:columns[target])
{
if (a[0][curr][col]=='+') possible++;
}
if (possible>1)
{
target--;for (int col=1;col<=m;col++) a[0][curr][col]='-';
}
curr++;
}
for (int col=1;col<=m;col++)
{
int starting=(col-1)%n+1,ending=(col-1)%n+1+n/2-1;
for (int row=starting;row<=min(n,ending);row++) a[1][row][col]='+';
for (int row=1;row+n<=ending;row++) a[1][row][col]='+';
}
for (int row=1;row<=n;row++)
{
int number=0;
for (int col=1;col<=m;col++)
{
if (a[1][row][col]=='+') number++;
}
rows[number].push_back(row);
}
target=m/2,curr=1;
while (curr<=m and target>=0)
{
int possible=0;
for (int row:rows[target])
{
if (a[1][row][curr]=='-') possible++;
}
if (possible>1)
{
target--;for (int row=1;row<=n;row++) a[1][row][curr]='+';
}
curr++;
}
int ans1=0,ans2=0;
for (int row=1;row<=n;row++)
{
int number1=0,number2=0;
for (int col=1;col<=m;col++)
{
if (a[0][row][col]=='+') number1++;
if (a[1][row][col]=='+') number2++;
}
if (number1>m/2) ans1++;
if (number2>m/2) ans2++;
}
for (int col=1;col<=m;col++)
{
int number1=0,number2=0;
for (int row=1;row<=n;row++)
{
if (a[0][row][col]=='-') number1++;
if (a[1][row][col]=='-') number2++;
}
if (number1>n/2) ans1++;
if (number2>n/2) ans2++;
}
if (ans1>ans2)
{
cout<<ans1<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[0][row][col];
cout<<endl;
}
}
else
{
cout<<ans2<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[1][row][col];
cout<<endl;
}
}
for (int col=1;col<=m;col++) columns[col].clear();
for (int row=1;row<=n;row++) rows[row].clear();
}
}