#include<bits/stdc++.h>
using namespace std;
const int MAXN=1024;
priority_queue< pair<int,int>,vector< pair<int,int> >,greater< pair<int,int> > > pq;
string s[MAXN];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
bool ck=false;
if(n>m) swap(n,m),ck=true;
int cnt=0,ans=m;
for(int i=1;i<=m;i++) if(0<(n-(n+2)/2)) pq.push({0,i}),cnt++;
for(int i=1;i<=n;i++)
{
s[i]=" ";
for(int j=1;j<=m;j++) s[i]+='-';
if(cnt>=(m+2)/2)
{
ans++;
vector< pair<int,int> > idx;
for(int j=1;j<=(m+2)/2;j++)
{
int a=pq.top().first,b=pq.top().second;
pq.pop(),s[i][b]='+',cnt--;
if(a+1<n-(n+2)/2) idx.push_back({a+1,b});
}
for(auto v:idx) pq.push(v),cnt++;
}
}
while(!pq.empty()) pq.pop();
cout<<ans<<"\n";
if(!ck)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) cout<<s[i][j];
cout<<"\n";
}
}
else
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++) if(s[j][i]=='+') cout<<'-';
else cout<<'+';
cout<<"\n";
}
}
}
}