## Algorithm

D. New Game with a Chess Piece
time limit per test
2 seconds
memory limit per test
64 megabytes
input
input.txt
output
output.txt

Petya and Vasya are inventing a new game that requires a rectangular board and one chess piece. At the beginning of the game the piece stands in the upper-left corner of the board. Two players move the piece in turns. Each turn the chess piece can be moved either one square to the right or one square down or jump k squares diagonally down and to the right. The player who can’t move the piece loses.

The guys haven’t yet thought what to call the game or the best size of the board for it. Your task is to write a program that can determine the outcome of the game depending on the board size.

Input

The first input line contains two integers t and k (1 ≤ t ≤ 201 ≤ k ≤ 109). Each of the following t lines contains two numbers nm — the board’s length and width (1 ≤ n, m ≤ 109).

Output

Output t lines that can determine the outcomes of the game on every board. Write «+» if the first player is a winner, and «-» otherwise.

Examples
input
Copy
`10 21 11 22 12 21 32 33 13 23 34 3`
output
Copy
`-++--+-+++`

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````#include <iostream>
#include <fstream>
#include <sstream>

bool firstWins(long n, long m, long k){

long min = (m < n) ? m : n;
if(min % (k + 1) == 0){return true;}
else if(k == 1 || (min / (k + 1)) % 2 == 0){return (m % 2) != (n % 2);}
else{return (m % 2) == (n % 2);}
}

int main(){

std::ifstream instream; instream.open("input.txt");
FILE * outputFile = fopen("output.txt","w");
long t, k; instream >> t >> k;
while(t--){
long n, m; instream >> n >> m;
fputs(firstWins(n, m, k) ? "+\n" : "-\n", outputFile);
}

instream.close();
fclose(outputFile);

return 0;
}``````
Copy The Code &

Input

cmd
10 2
1 1
1 2
2 1
2 2
1 3
2 3
3 1
3 2
3 3
4 3

Output

cmd
-
+
+
-
-
+
-
+
+
+