// Starcraft 2 enjoyer //
#include <bits/stdc++.h>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
#define LSOne(X) ((X) & -(X))
const int N = 3e5 + 5;
const int M = 1 << 10 + 5;
const int B = 18;
const long long K = 2;
const int LG = 60;
const long long INF = 1e18 + 5;
const int C = 26;
const int MOD = 1e9 + 7;
int n, m;
vector<pair<int, vector<vector<char>>>> v;
vector<vector<char>> cur;
void print(vector<vector<char>> v)
{
for(int x = 0; x < n; x++)
{
for(int y = 0; y < m; y++)
{
cout << v[x][y];
}
cout << "\n";
}
}
inline void solve()
{
cin >> n >> m;
v.clear();
cur.assign(n, vector<char>(m, '0'));
for (int x = 0; x < n - (n - 1) / 2; x++)
{
for (int y = 0; y < m; y++)
{
cur[x][y] = '-';
}
}
for (int x = n - (n - 1)/2; x < n; x++)
{
for (int y = 0; y < m; y++)
{
cur[x][y] = '+';
}
}
v.push_back({(n - 1) / 2 + m, cur});
for (int x = 0; x < n; x++)
{
for (int y = 0; y < m; y++)
{
if (y < (m - 1) / 2)
{
cur[x][y] = '-';
}
else
{
cur[x][y] = '+';
}
}
}
v.push_back({n + (m - 1) / 2, cur});
for (int x = 0; x < (n - 1) / 2; x++)
{
for (int y = 0; y < m; y++)
{
if (y < (m + 2) / 2)
{
cur[x][y] = '+';
}
else
{
cur[x][y] = '-';
}
}
}
for (int x = (n - 1) / 2; x < 2 * ((n - 1) / 2); x++)
{
for (int y = 0; y < m; y++)
{
if (y < m - (m + 2) / 2)
{
cur[x][y] = '-';
}
else
{
cur[x][y] = '+';
}
}
}
for (int x = 2 * ((n - 1) / 2); x < n; x++)
{
for (int y = 0; y < m; y++)
{
cur[x][y] = '-';
}
}
v.push_back({m - 1 - (m % 2 == 0) + n - 1 - (n % 2 == 0), cur});
sort(v.rbegin(), v.rend());
cout << v[0].first << "\n";
for(int x = 0; x < n; x++)
{
for(int y = 0; y < m; y++)
{
cout << v[0].second[x][y];
}
cout << "\n";
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
for (int x = 1; x <= t; x++)
{
solve();
}
return 0;
}