atcoder#AGC015F. [AGC015F] Kenus the Ancient Greek

[AGC015F] Kenus the Ancient Greek

Score : 17001700 points

Problem Statement

Kenus, the organizer of International Euclidean Olympiad, is seeking a pair of two integers that requires many steps to find its greatest common divisor using the Euclidean algorithm.

You are given QQ queries. The ii-th query is represented as a pair of two integers XiX_i and YiY_i, and asks you the following: among all pairs of two integers (x,y)(x,y) such that 1xXi1 \leq x \leq X_i and 1yYi1 \leq y \leq Y_i, find the maximum Euclidean step count (defined below), and how many pairs have the maximum step count, modulo 109+710^9+7.

Process all the queries. Here, the Euclidean step count of a pair of two non-negative integers (a,b)(a,b) is defined as follows:

  • (a,b)(a,b) and (b,a)(b,a) have the same Euclidean step count.
  • (0,a)(0,a) has a Euclidean step count of 00.
  • If a>0a > 0 and aba \leq b, let pp and qq be a unique pair of integers such that b=pa+qb=pa+q and 0q<a0 \leq q < a. Then, the Euclidean step count of (a,b)(a,b) is the Euclidean step count of (q,a)(q,a) plus 11.

Constraints

  • 1Q3×1051 \leq Q \leq 3 \times 10^5
  • 1Xi,Yi1018(1iQ)1 \leq X_i,Y_i \leq 10^{18}(1 \leq i \leq Q)

Input

The input is given from Standard Input in the following format:

QQ

X1X_1 Y1Y_1

::

XQX_Q YQY_Q

Output

For each query, print the maximum Euclidean step count, and the number of the pairs that have the maximum step count, modulo 109+710^9+7, with a space in between.

3
4 4
6 10
12 11
2 4
4 1
4 7

In the first query, (2,3)(2,3), (3,2)(3,2), (3,4)(3,4) and (4,3)(4,3) have a Euclidean step count of 22. No pairs have a step count of more than 22.

In the second query, (5,8)(5,8) has a Euclidean step count of 44.

In the third query, (5,8)(5,8), (8,5)(8,5), (7,11)(7,11), (8,11)(8,11), (11,7)(11,7), (11,8)(11,8), (12,7)(12,7) have a Euclidean step count of 44.

10
1 1
2 2
5 1000000000000000000
7 3
1 334334334334334334
23847657 23458792534
111111111 111111111
7 7
4 19
9 10
1 1
1 4
4 600000013
3 1
1 993994017
35 37447
38 2
3 6
3 9
4 2