import java.io.*; import java.util.*;
public class stones{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
static int MOD=998244353;
static int[] rk, p;
public static void main(String[] args){
FastReader br=new FastReader();
int T=br.nextInt();
StringBuilder sb; int d;
while(T>0){
T--; sb=new StringBuilder();
int N=br.nextInt(); int M=br.nextInt();
if(N==1){
System.out.println(M);
for (int i = 0; i < M; i++) {
sb.append('-');
}
}else if(M==1){
System.out.println(N);
for (int i = 0; i < N; i++) {
sb.append('+').append("\n");
}
}else if(N==2){
System.out.println(M);
for (int i = 0; i < M; i++) {
sb.append('-');
}
sb.append("\n");
for (int i = 0; i < M; i++) {
sb.append('-');
}
}else if(M==2){
System.out.println(N);
for (int i = 0; i < N; i++) {
sb.append('+').append('+').append("\n");
}
}else{//M,N>2
if(M%2==1 && N%2==1){
sb.append(M+N-2).append("\n");
sb.append('+');
for (int i = 0; i < M-1; i++) {
sb.append('-');
}
sb.append("\n");
for (int i = 0; i < N-1; i++) {
sb.append('+');
for (int j = 0; j < M-1; j++) {
if((i+j)%2==0){
sb.append('+');
}else{
sb.append('-');
}
}
sb.append("\n");
}
}else if(N%2==1){
if(M/2 >= N-2){
sb.append(M+N-2).append("\n");
for (int i = 0; i < N-2; i++) {
for (int j = 0; j < 2*(N-2); j++) {
d=(j-(N-3)*i+2000*(N-2))%(2*N-4);
if(d<N-3)sb.append('-');
else sb.append('+');
}
for (int j = 2*(N-2); j < M; j++) {
if((i+j)%2==0)sb.append('+');
else sb.append('-');
}
sb.append("\n");
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < M; j++) {sb.append('-');}
sb.append("\n");
}
}else{
sb.append(M+N-3).append("\n");
for (int j = 0; j < M; j++) {sb.append('-');}
sb.append("\n");
for (int i = 0; i < N-1; i++) {
sb.append("++");
for (int j = 0; j < M-2; j++) {
if((i+j)%2==0)sb.append('-');
else sb.append('+');
}
sb.append("\n");
}
}
}else if(M%2==1){
if(M==3){
for (int i = 0; i < N; i++) {
sb.append("++- \n");
}
}else if(N/2 < M-2){
sb.append((M+N-3)+"\n");
for(int i=0;i<M;i++)sb.append('-');
sb.append("\n");
for(int i=0;i<M;i++)sb.append('-');
sb.append("\n");
for (int i = 0; i < N-2; i++) {
sb.append('+');
for (int j = 0; j < M-1; j++) {
if((i+j)%2==0)sb.append('-');
else sb.append('+');
}
sb.append("\n");
}
}else{
sb.append((M+N-2)+"\n");
for (int i = 0; i < 2*(M-2); i++) {
sb.append("++");
for (int j = 0; j < M-2; j++) {
d=(i-(M-3)*j+2000*(M-2))%(2*M-4);
if(d<M-3)sb.append('+');
else sb.append('-');
}
sb.append("\n");
}
for (int i = 2*(M-2); i < N; i++) {
for (int j = 0; j < M; j++) {
if((i+j)%2==0)sb.append('-');
else sb.append('+');
}
sb.append("\n");
}
}
}else{
//M,N are both even
if(M==4){
sb.append(N+1+"\n");
for (int i = 0; i < N; i++) {
sb.append("+++- \n");
}
}else if(N==4){
sb.append(M+1+"\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < M; j++) {
sb.append('-');
}
sb.append("\n");
}
for (int j = 0; j < M; j++) {
sb.append('+');
}
}else if(M/2 > N-4){
sb.append(M+N-3).append("\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < M; j++) {
sb.append('-');
}
sb.append("\n");
}
for (int i = 0; i < N-3; i++) {
for (int j = 0; j < 2*(N-3); j++) {
d=(j-(N-4)*i+2000*(N-3))%(2*N-6);
if(d<N-4)sb.append('-');
else sb.append('+');
}
for (int j = 2*(N-3); j < M; j++) {
if((i+j)%2==0)sb.append('-');
else sb.append('+');
}
sb.append("\n");
}
}else if(N/2 > M-4){
sb.append(M+N-3+"\n");
for (int i = 0; i < 2*(M-3); i++) {
sb.append("+++");
for (int j = 0; j < M-3; j++) {
d=(i-(M-4)*j+2000*(M-3))%(2*M-6);
if(d<M-4)sb.append('+');
else sb.append('-');
}
sb.append("\n");
}
for (int i = 2*(M-3); i < N; i++) {
sb.append("+++");
for (int j = 0; j < M-3; j++) {
if((i+j)%2==0)sb.append('-');
else sb.append('+');
}
sb.append("\n");
}
}else{
sb.append((M+N-4)+"\n");
for(int i=0;i<M;i++)sb.append('-');
sb.append("\n");
for(int i=0;i<M;i++)sb.append('-');
sb.append("\n");
for (int i = 0; i < N-2; i++) {
sb.append("++");
for (int j = 0; j < M-2; j++) {
if((i+j)%2==0)sb.append('-');
else sb.append('+');
}
sb.append("\n");
}
}
}
}
System.out.println(sb.toString());
}
}
}
//Debugging:
//Are you sure your algorithm is correct?
//Bounds: long
//Special cases: n=0,1?
//Make sure you remove your debugging code before you submit!
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Incorrect |
125 ms |
9584 KB |
Expected integer, but "++-" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
164 ms |
9744 KB |
Expected integer, but "++-" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Incorrect |
125 ms |
9584 KB |
Expected integer, but "++-" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
17840 KB |
Output is correct |
2 |
Correct |
236 ms |
18204 KB |
Output is correct |
3 |
Correct |
220 ms |
18692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
463 ms |
23632 KB |
Output is correct |
2 |
Correct |
287 ms |
20644 KB |
Output is correct |
3 |
Correct |
258 ms |
19776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Incorrect |
125 ms |
9584 KB |
Expected integer, but "++-" found |