#P1359A. Berland Poker
Berland Poker
Description
The game of Berland poker is played with a deck of cards, of which are jokers. players play this game ( is divisible by ).
At the beginning of the game, each player takes cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he gets the number of points equal to , where is the number of jokers in the winner's hand, and is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers, all of them are winners and they get points.
Here are some examples:
- , , . If one player gets jokers and plain card, and another player gets jokers and plain cards, then the first player is the winner and gets points;
- , , . Two players get plain cards, and the other two players get jokers, so both of them are winners and get points;
- , , . If the first player gets jokers, the second player gets joker and plain cards, and the third player gets jokers and plain card, then the first player is the winner, and he gets point;
- , , . Since there are no jokers, everyone gets jokers, everyone is a winner, and everyone gets points.
Given , and , calculate the maximum number of points a player can get for winning the game.
The first line of the input contains one integer () — the number of test cases.
Then the test cases follow. Each test case contains three integers , and (, , , is a divisors of ).
For each test case, print one integer — the maximum number of points a player can get for winning the game.
Input
The first line of the input contains one integer () — the number of test cases.
Then the test cases follow. Each test case contains three integers , and (, , , is a divisors of ).
Output
For each test case, print one integer — the maximum number of points a player can get for winning the game.
Note
Test cases of the example are described in the statement.