#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define dur exit(0)
#define dur1 return(0)
#define minus jj
const int N = 1e3 + 5;
vector <pii> v;
char jogap[N][N];
int minus[N];
int main () {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin >> t;
	while ( t-- ) {
		int n, m;
		cin >> n >> m;
		int gir = 0;
		if (m < n) {
			swap (n, m);
			gir = 1;
		}
		int y = m * ((n + 1) / 2 - 1);
		int jog = y / (m / 2 + 1);
		cout << n + jog << "\n";
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				jogap[i][j] = '-';
			}
		}
		for (int i = 1; i <= jog; ++i) {
			for (int j = 1; j <= m; ++j) {
				v.pb ({minus[j], j});
			}
			sort (v.begin(), v.end());
			for (int j = 1; j <= (n + 1) / 2 + 1; ++j) {
				minus[v[j - 1].ss]++;
				jogap[i][v[j - 1].ss] = '+';
			}
			v.clear();
		}
		if (gir) {
//			for (int i = 1; i <= n; ++i) {
//				for (int j = 1; j <= m; ++j) {
//					if (jogap[i][j] == '-') jogap[i][j] = '+';
//					else jogap[i][j] = '+';
//				}
//				cout << "\n";
//			}
			int sana = 0;
			for (int i = 1; i <= n; ++i) {
				for (int j = 1; j <= m; ++j) {
					cout << jogap[i][j];
					sana++;
					if (sana == n) {
						cout << "\n";
						sana = 0;
					}
				}
			}			
		}
		else {
			for (int i = 1; i <= n; ++i) {
				for (int j = 1; j <= m; ++j) {
					cout << jogap[i][j];
				}
				cout << "\n";
			}
		}
		cout << "\n";
		for (int i = 1; i <= m; ++i) {
			minus[i] = 0;
		}
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |