#include <bits/stdc++.h>
using namespace std;
#define MAXN 1001
#define int long long
int t,n,m;
char a[MAXN][MAXN];
vector<int> columns[MAXN];
int32_t main()
{
cin>>t;
for (int test=0;test<t;test++)
{
cin>>n>>m;bool swaped=false;
if (n>m) {swap(n,m);swaped=true;}
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='+';
}
for (int row=1;row<=n;row++)
{
int ending=row+m/2-1;
for (int col=row;col<=min(m,ending);col++) a[row][col]='-';
for (int col=1;col+m<=ending;col++) a[row][col]='-';
}
for (int col=1;col<=m;col++)
{
int number=0;
for (int row=1;row<=n;row++)
{
if (a[row][col]=='-') number++;
}
columns[number].push_back(col);
}
int target=n/2,curr=1;
while (target>=0 and curr<=n)
{
int starting=curr,ending=curr+m/2-1;int number=0;
for (int col:columns[target])
{
if (starting<=col and col<=ending) continue;
if (col+m<=ending) continue;
number++;
}
if (number>1)
{
target--;for (int col=1;col<=m;col++) a[curr][col]='-';
}
curr++;
}
int answer=0;
for (int row=1;row<=n;row++)
{
int number=0;
for (int col=1;col<=m;col++)
{
if (a[row][col]=='+') number++;
}
if (number>m/2) answer++;
}
for (int col=1;col<=m;col++)
{
int number=0;
for (int row=1;row<=n;row++)
{
if (a[row][col]=='-') number++;
}
if (number>n/2) answer++;
}
cout<<answer<<endl;
if (!swaped)
{
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
}
else
{
for (int col=1;col<=m;col++)
{
for (int row=1;row<=n;row++) cout<<a[row][col];
cout<<endl;
}
}
for (int num=0;num<=n;num++) columns[num].clear();
}
}