Problem: Chaneka, a gamer kid, invented a new gaming controller called joyboard. Interestingly, the joyboard she invented can only be used to play one game.
The joyboard has a screen containing slots numbered from to from left to right. The slots are going to be filled with an array of non-negative integers . Chaneka, as the player, must assign with an integer between and inclusive. Then, for each from to , the value of will be equal to the remainder of dividing (the adjacent value to the right) by . In other words, .
Chaneka wants it such that after every slot is assigned with an integer, there are exactly distinct values in the entire screen (among all slots). How many valid ways are there for assigning a non-negative integer into slot ?
Input Format: Each test contains multiple test cases. The first line contains an integer () — the number of test cases. The following lines contain the description of each test case.
The only line of each test case contains three integers , , and (; ; ) — there are slots, the integer assigned in slot must not be bigger than , and there should be exactly distinct values.
Output Format: For each test case, output a line containing an integer representing the number of valid ways for assigning a non-negative integer into slot .
Note: In the first test case, one of the possible ways for Chaneka is to choose . If she does that, then:
- There are distinct values.
In the second test case, the possible way for Chaneka is to choose . If she does that, then . There is only distinct value.
In the third test case, there is no possible way for assigning a non-negative integer into slot .