For the first test case of the sample input, there are 2 segments in a 2*2 lattice.
Because two endpoint couldn’t coincide, two segments must be (0,y)-(1,y) and (x,0)-(x,1). (x, y∈{0,1})
Thus, they always intersect at (x,y). As an irreducible fraction the answer is 1/1, where q = 1, so we should output an integer 1 instead.