Under construction

Still being built. Things may change

Kangaroo Race

Time limit5sMemory limit1024 MB

Summary
Given a cyclic track of n segments and a kangaroo at segment x, find the fewest jumps of y(y-1) segments needed to reach segment 1, or report impossible.
Level

Medium7 of 10

Topics
Math, Number theory
Solved
No attempts yet

Problem

The country of Austria is known for its large kangaroo population. To stay in good shape, each kangaroo has its own athletics track for practicing for the Annual Austrian Pogostick Jumping Event.

Each athletics track consists of nn segments, each 11 meter long. The segments are numbered from 11 to nn in order. The track is cyclic, so segment 11 comes right after segment nn.

On each track, a kangaroo is located in one of the segments. The kangaroo can make a finite number of jumps. In each jump, if the kangaroo is in segment yy, it jumps y(y−1)y(y-1) segments ahead. Find the minimum number of jumps the kangaroo needs to reach segment 11.

Input

The first line contains an integer kk (1≤k≤1051 \leq k \leq 10^5), the number of kangaroos. Each of the next kk lines contains two integers nn and xx (1≤x≤n≤10181 \leq x \leq n \leq 10^{18}), the number of segments on the track and the kangaroo's initial position on that track.

Output

For each kangaroo, if it can reach segment 11 in a finite number of jumps, output the minimum number of jumps needed. Otherwise, output impossible.

Hint

Intermediate values in your calculation may exceed the range of 64-bit integers. To store them, use __int128 in C++ or java.math.BigInteger in Java or Kotlin. Python integers have arbitrary size by default, so no special handling is needed.

Examples1

  1. Example 1

    Input
    4
    5 2
    6 2
    8 3
    12345678910 1
    
    Expected output
    2
    impossible
    1
    0