Kaosar and EM ( > w < )#12365

Kaosar and EM ( > w < )

2 seconds
256 megabytes
Medium

You are given integers , and you have to say how many integer are there in range [l,r]

such that

x\equiv \lfloor \sqrt x \rfloor \mod p

use sqrt decomposition ds

Input

The first line contains a single integer (1\le t\le 10^3) the total number of test cases.

Each test case contains integers , (0\le l\le r\le 10^9) and (1\le p\le 10^5).

Output

Print the total number of in the range [l,r].

Examples

Example 1

Loading
Loading

Note

In first test case 1,5,8,9 satisfy the condition so the answer is .

Scoring

  1. Subtask ( points) : (p=1)

  2. Subtask ( points) : r\le 10^3

  3. Subtask ( points) : \sum r-l \le 10^6

  4. Subtask ( points) : No additional constraints.