Under construction

Still being built. Things may change

Flipping and cutting (Easy)

Time limit1sMemory limit1024 MB

Summary
Given a circle with circumference c and a step length sqrt(s), find the minimum number of wedge flips after which the circle is fully black again, or report that it never happens.
Level

Medium6 of 10

Topics
Number theory, Math, Simulation
Solved
No attempts yet

Problem

On the table we have a perfect circle cut out of paper. The circle is all black from the top and all white from the bottom. The circumference of the circle is a positive integer cc.

We also have a pair of scissors. We will use the scissors to cut the circle. At the beginning we choose an arbitrary point on the boundary of the circle (called the active point) and make a straight cut from that point to the center of the circle.

Next, we choose a positive integer ss (with s<c2s < c^2): the square of our step length. Then we perform an infinite sequence of rounds. Each round consists of these steps:

  1. Find a new point by starting at the current active point and measuring the distance s\sqrt{s} along the boundary of the circle, counter-clockwise.
  2. Make a straight cut from the new point to the center of the circle.
  3. We now have a wedge (a sector of the circle) that starts with the cut from the active point to the center and continues counter-clockwise to the cut from the new point to the center. The inside of the wedge may also contain other cuts.
  4. We lift the entire wedge from the table, flip it upside down and return it to its place. If the wedge already consists of multiple pieces, their order is reversed by this operation.
  5. The new point becomes the active point for the next round.

The figure below illustrates the first four rounds for c=360c = 360 and s=100\sqrt{s}=100. Pay close attention to what happens in the fourth round.

For some pairs (c,s)(c, s) the circle becomes completely black again after finitely many rounds. Find all such pairs, and for each one, find the smallest number of rounds after which this happens.

A circle is completely black if each point of the top side is black or lies on one of the cuts. In other words, the color of points lying directly on a cut does not matter.

Input

The first line of the input contains an integer tt, the number of test cases. Each test case is preceded by a blank line.

Each test case consists of a single line with the positive integers cc and ss. You may assume s<c2s < c^2, c≤1000c \le 1000, and that s\sqrt{s} is an integer.

Output

If the process never returns to a completely black circle, output a single line with the text never. Otherwise, output a single line with the smallest positive number of rounds after which the circle is again completely black.

Hint

In the first example the circumference is 360 and each wedge contains 60 units of the circumference. After six rounds every part of the circle has been flipped exactly once, and after another six rounds everything is back to where it started.

The second example matches the situation in the figure above. It takes 24 rounds to return to an all-black circle.

In the third example each round flips 5/6 of the circle. Surprisingly, the circle is completely black again after four rounds.

Examples1

  1. Example 1

    Input
    3
    
    360 3600
    
    360 10000
    
    360 90000
    
    Expected output
    12
    24
    4