#include <bits/stdc++.h>
#define int int64_t
using namespace std;
static const int MOD = 998244353;
inline void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n,vector<char>(m));
    int X = (n & 1 ? n/2 : n/2-1) + m;
    int Y = (m & 1 ? m/2 : m/2-1) + n;
    int Z = 0;
    int u = 0, v = 0;
    for(int A = n/2+1;A <= n;++ A){
        for(int B = m/2+1; B <= m;++ B){
            bool flag1 = false;
            bool flag2 = false;
            if(n & 1) {
                flag1 = (A >= ((A-n/2)<<1));
            } else flag1 = (A >= ((A-n/2)<<1) + 2);
            if(m & 1) {
                flag2 = (B >= ((B-m/2)<<1));
            } else flag2 = (B >= ((B-m/2)<<1) + 2);
            if(flag1 and flag2) {
                if(A+B > Z) {
                    u=A;
                    v=B;
                }
                Z = max(Z, A+B);
            }
        }
    }
    int ind = max({X,Y,Z});
    if(ind == Y) {
        cout << ind << "\n";
        for(int i = 0; i < n;++ i){
            if(m & 1) {
                for(int i = 0; i < m/2;++ i){
                    cout << "-";
                }
                for(int i = m/2; i < m;++ i){
                    cout << "+";
                }
            } else {
                for(int i = 0; i < m/2-1;++ i){
                    cout << "-";
                }
                for(int i = m/2-1; i < m;++ i){
                    cout << "+";
                }
            }
            cout << "\n";
        }
    } else if(ind == X) {
        cout << ind << "\n";
        for(int i = 0; i < n;++ i){
            if(n & 1) {
                if(i < n/2){
                    for(int j = 0; j < m;++ j){
                        cout << "+";
                    }
                } else {
                    for(int j = 0; j < m;++ j){
                        cout << "-";
                    }
                }
            } else {
                if(i < n/2-1){
                    for(int j = 0; j < m;++ j){
                        cout << "+";
                    }
                } else {
                    for(int j = 0; j < m;++ j){
                        cout << "-";
                    }
                }
            }
            cout << "\n";
        }
    } else {
        for(int i = 0; i < n;++ i){
            for(int j = 0; j < m;++ j){
                if(j < u) {
                    a[i][j] = '+';
                } else a[i][j] = '-';
            }
        }
        int q = (n & 1 ? u-n/2 : u-n/2+1);
        int p = (m & 1 ? v-m/2 : v-m/2+1);
        for(int j = u-1; j > u-1-q;-- j){
            for(int i = 0; i < n/2;++ i){
                a[i][j] = '-';
            }
        }
        for(int j = u-1-q; j > u-1-q-q;-- j){
            for(int i = n/2; i < u;++ i){
                a[i][j] = '-';
            }
        }
        for(int i = 0; i < n;++ i){
            for(int j = 0; j < n;++ j){
                cout << a[i][j];
            }
            cout << "\n";
        }
    }
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int _ = 1; 
    cin >> _;
    while (_--) {
        solve();
    }
}
| # | 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... |