#include <bits/stdc++.h>
using namespace std;
#define MAXN 1001
int t,n,m;
char a[MAXN][MAXN];
int main()
{
cin>>t;
for (int test=0;test<t;test++)
{
cin>>n>>m;
if (min(n,m)==n and n==5)
{
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='+';
}
for (int col=1;col<=m;col++) a[1][col]=a[2][col]='-';
int curr=3;
for (int col=1;col<=m;col++)
{
a[curr][col]='-';curr++;
if (curr==6) curr=3;
}
cout<<n+m-2<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
continue;
}
else if (min(n,m)==m and m==5)
{
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='-';
}
for (int row=1;row<=n;row++) a[row][1]=a[row][2]='+';
int curr=3;
for (int row=1;row<=n;row++)
{
a[row][curr]='+';curr++;
if (curr==6) curr=3;
}
cout<<n+m-2<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
continue;
}
else if (min(n,m)<5)
{
if (n<=m)
{
int targeta=(n+1)/2-1,numa=m/2+1;
for (int row=1;row<=targeta;row++)
{
for (int col=1;col<=m;col++)
{
if (col<=numa) a[row][col]='+';
else a[row][col]='-';
}
}
for (int row=targeta+1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='-';
}
}
else
{
int targetb=(m+1)/2-1,numb=n/2+1;
for (int col=1;col<=targetb;col++)
{
for (int row=1;row<=n;row++)
{
if (row<=numb) a[row][col]='-';
else a[row][col]='+';
}
}
for (int col=targetb+1;col<=m;col++)
{
for (int row=1;row<=n;row++) a[row][col]='+';
}
}
cout<<max(n,m)+(min(n,m)+1)/2-1<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
continue;
}
if (min(n,m)==n and n==6)
{
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='+';
}
for (int col=1;col<=m;col++) a[1][col]=a[2][col]=a[3][col]='-';
int curr=4;
for (int col=1;col<=m;col++)
{
a[curr][col]='-';curr++;
if (curr==7) curr=4;
}
cout<<n+m-3<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
continue;
}
if (min(n,m)==m and m==6)
{
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='-';
}
for (int row=1;row<=n;row++) a[row][1]=a[row][2]=a[row][3]='+';
int curr=4;
for (int row=1;row<=n;row++)
{
a[row][curr]='+';curr++;
if (curr==7) curr=4;
}
cout<<n+m-3<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
continue;
}
int answer=n+m-2;
if (n%2==0 and m%2==0 and n==m) answer-=2;
else if (n%2==0 or m%2==0) answer--;
if (n<=m)
{
int potrebno=n/2+1;int curn=n,curm=m;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='+';
}
for (int col=1;col<=m;col++) a[n-1][col]=a[n][col]='-';
potrebno-=2;curn-=2;
if (n%2==0)
{
potrebno--;curn--;for (int col=1;col<=m;col++) a[n-2][col]='-';
}
if (m%2==0 and n==m)
{
curm--;for (int row=1;row<=curn;row++) a[row][m]='+';
}
int curr=1;
for (int col=1;col<=curm;col++)
{
int number=0;
while (number<potrebno)
{
a[curr][col]='-';number++;curr++;
if (curr==curn+1) curr=1;
}
}
}
else
{
int potrebno=m/2+1,curn=n,curm=m;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) a[row][col]='-';
}
for (int row=1;row<=n;row++) a[row][m-1]=a[row][m]='+';
potrebno-=2;curm-=2;
if (m%2==0)
{
potrebno--;curm--;for (int row=1;row<=n;row++) a[row][m-2]='+';
}
if (n%2==0 and n==m)
{
curn--;for (int col=1;col<=curm;col++) a[n][col]='-';
}
int curr=1;
for (int row=1;row<=curn;row++)
{
int number=0;
while (number<potrebno)
{
a[row][curr]='+';number++;curr++;
if (curr==curm+1) curr=1;
}
}
}
cout<<answer<<endl;
for (int row=1;row<=n;row++)
{
for (int col=1;col<=m;col++) cout<<a[row][col];
cout<<endl;
}
}
}