Lame Queen Game

All submissions for this problem are available.
Code and Chef play a game on the set of all points with positive integer coordinates of the usual coordinate plane. Initially the lame queen stands in the point with coordinates (x_{0}, y_{0}) or shortly: in the point (x_{0}, y_{0}). Players alternate moves. Code moves first. During each move the player can move the queen from the point (x, y) to the point (x  a, y), (x, y  a) or (x  a, y  a) for some positive integer a, provided that the new point has positive coordinates. But since the queen is lame she possibly can't make all diagonal moves. Namely she can move from the point (x, y) to the point (x  a, y  a) only if a is divisible by d, where d is some positive integer that is called the queen lameness. So if d = 2 the queen can move diagonally from the point (x, y) only to the points (x  2, y  2), (x  4, y  4), (x  6, y  6) and so on. However if d = 1 then the queen becomes the usual chess queen. The first player who can't make a valid move loses the game. Both players play optimally in their respective moves.
After playing this game for some time Chef realizes that he loses almost always. Now he wants to know what is the probability that he wins if initial point (x_{0}, y_{0}) is chosen randomly from the rectangle x_{1} <= x_{0} <= x_{2}, y_{1} <= y_{0} <= y_{2}. But I should warn that he wants to know this for a large number of rectangles.
Input
The first line contains two space separated positive integers d and T, the queen lameness and the number of rectangles for which Chef wants to know the answer. Each of the next T lines contains four space separated positive integers x_{1}, y_{1}, x_{2}, y_{2} the coordinates of rectangle corners.
Output
For each rectangle from the input file, output a single line containing the probability in the form of an irreducible fraction that Chef wins if the initial cell is chosen randomly from this rectangle.
Constraints
1 <= d <= 20
1 <= T <= 100000
1 <= x_{1} <= x_{2} <= 200000
1 <= y_{1} <= y_{2} <= 200000
Example
Input: 1 4 1 1 4 4 2 4 5 8 3 7 10 10 5 8 5 8 Output: 3/16 1/10 1/32 1/1
Explanation
For the first rectangle Chef wins in three cases out of 16. Namely when the starting point is (1,1), (2,3) or (3,2).
The fourth rectangle is lucky. It contains only one point and this one is winning for Chef.
Author:  anton_lunyov 
Tester:  pieguy 
Editorial  http://discuss.codechef.com/problems/LAMQUGAM 
Tags  anton_lunyov, cook15, hard 
Date Added:  13102011 
Time Limit:  0.567887 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 