#CT0000063. Nhiều truy vấn đếm số chính phương (Multiple Perfect-Square Count Queries)

Nhiều truy vấn đếm số chính phương (Multiple Perfect-Square Count Queries)

Multiple Perfect-Square Count Queries

Version: Phuoc Hung OJ Extended

Problem Statement

You are given QQ integer intervals. Query ii is described by two positive integers LiL_i and RiR_i with Li≤RiL_i \le R_i.

For each query, determine the number of perfect squares in [Li,Ri][L_i,R_i]. The queries are independent and must be answered in their input order.

Input

The first line contains the positive integer QQ, the number of queries.

The next QQ lines each contain two positive integers LiL_i and RiR_i.

Output

Print QQ lines. Line ii contains the number of perfect squares in [Li,Ri][L_i,R_i].

Subtasks

  • Subtask 1 (20%): 1≤Q≤1001 \le Q \le 100 and 1≤Li≤Ri≤1061 \le L_i \le R_i \le 10^6.
  • Subtask 2 (30%): 1≤Q≤2⋅1051 \le Q \le 2\cdot10^5 and 1≤Li≤Ri≤10121 \le L_i \le R_i \le 10^{12}.
  • Subtask 3 (50%): 1≤Q≤2⋅1051 \le Q \le 2\cdot10^5 and 1≤Li≤Ri≤10181 \le L_i \le R_i \le 10^{18}.

Examples

Example 1

Input

4
1 10
15 35
36 36
37 63

Output

3
2
1
1

Explanation

The four intervals contain {1,4,9}\{1,4,9\}, {16,25}\{16,25\}, {36}\{36\}, and {49}\{49\} respectively. Thus the answers are 3,2,1,13,2,1,1.

Example 2

Input

4
1 1
2 3
99 100
100 121

Output

1
0
1
2

Explanation

[1,1][1,1] contains 11; [2,3][2,3] contains no perfect square; [99,100][99,100] contains only 100100; and [100,121][100,121] contains both 100100 and 121121.

Example 3

Input

3
1000000000000000000 1000000000000000000
999999998000000001 1000000000000000000
999999998000000002 999999999999999999

Output

1
2
0

Explanation

The two consecutive perfect squares nearest the upper limit are (109−1)2=999999998000000001(10^9-1)^2=999999998000000001 and (109)2=1018(10^9)^2=10^{18}. The first query contains the latter; the second contains both; the third lies strictly between them and contains none.