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){
sb.append(N+1+"\n");
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++) {
sb.append("++");
for (int j = 0; j < M-2; 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 |
74 ms |
8936 KB |
Output is correct |
2 |
Correct |
111 ms |
9704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
10732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
8936 KB |
Output is correct |
2 |
Correct |
111 ms |
9704 KB |
Output is correct |
3 |
Correct |
193 ms |
10732 KB |
Output is correct |
4 |
Correct |
220 ms |
10948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
17956 KB |
Output is correct |
2 |
Correct |
204 ms |
18340 KB |
Output is correct |
3 |
Correct |
214 ms |
18824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
401 ms |
23500 KB |
Output is correct |
2 |
Correct |
267 ms |
20432 KB |
Output is correct |
3 |
Correct |
289 ms |
19792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
8936 KB |
Output is correct |
2 |
Correct |
111 ms |
9704 KB |
Output is correct |
3 |
Correct |
193 ms |
10732 KB |
Output is correct |
4 |
Correct |
220 ms |
10948 KB |
Output is correct |
5 |
Correct |
246 ms |
17956 KB |
Output is correct |
6 |
Correct |
204 ms |
18340 KB |
Output is correct |
7 |
Correct |
214 ms |
18824 KB |
Output is correct |
8 |
Correct |
401 ms |
23500 KB |
Output is correct |
9 |
Correct |
267 ms |
20432 KB |
Output is correct |
10 |
Correct |
289 ms |
19792 KB |
Output is correct |
11 |
Correct |
573 ms |
33076 KB |
Output is correct |
12 |
Correct |
271 ms |
21384 KB |
Output is correct |
13 |
Correct |
299 ms |
21308 KB |
Output is correct |
14 |
Correct |
295 ms |
19832 KB |
Output is correct |
15 |
Correct |
194 ms |
15336 KB |
Output is correct |
16 |
Correct |
206 ms |
14832 KB |
Output is correct |
17 |
Correct |
149 ms |
12776 KB |
Output is correct |