Under construction

Still being built. Things may change

Russian Roulette (Hard)

Time limit5sMemory limit1024 MB

Summary
Given n players, c chambers, and k passes per empty shot, find the starting seat with the best survival chance and its probability modulo 1000000009.
Level

Hard8 of 10

Topics
Dynamic programming, Probability, Math
Solved
No attempts yet

Problem

You went out to celebrate with your n−1n-1 friends. You all got drunk and decided that playing Russian roulette with a paintball gun sounds like a great idea.

The gun is a revolver with cc chambers (c≥nc \ge n). Exactly n−1n-1 of those chambers contain a paintball, and all others are empty.

The game has one other parameter: a positive integer constant kk.

At the beginning of the game, all nn players stand in a circle. Number the players 0 through n−1n-1 in clockwise order. Player 0 takes the gun. The game repeats the following three steps until the gun becomes empty:

  1. The person holding the gun shoots themselves. They spin the cylinder to choose one of the chambers uniformly at random, point the gun at themselves, and pull the trigger.
  2. If the chosen chamber was empty, exactly kk rounds of passing follow. In each round, the holder passes the gun clockwise to the next player still in the game.
  3. If the chamber contained a paintball, the player is hit and loses the game. The gun passes clockwise to the next player still in the game, and the hit player leaves the game.

The winner is the only player who is not shot.

For given nn, cc, and kk, compute where you should stand at the beginning to maximize your probability of winning. Also compute the exact value of that probability.

Input

The first line contains an integer tt, the number of test cases. Each test case is preceded by a blank line.

Each case is a single line with the integers nn, cc, and kk. It is guaranteed that 1≤k≤n≤c1 \le k \le n \le c and c≤1000c \le 1000.

Output

For each test case, print one line with two space-separated numbers. The first is the position at the beginning of the game that maximizes your probability of winning. The second is a number that encodes the probability of winning from that position.

If several positions are optimal, print the smallest one.

Let the maximum winning probability be the irreducible fraction p/qp/q. Print p⋅q−1 mod (109+9)p \cdot q^{-1} \bmod (10^9+9), where q−1q^{-1} is the modular inverse of qq modulo 109+910^9+9. The maximum probability is guaranteed to be expressible as such a fraction, and the modular inverse of qq is guaranteed to exist.

Hint

The exact answer for the first test case is 33/6533/65. Since 65−1≡323076926(mod109+9)65^{-1} \equiv 323076926 \pmod{10^9+9}, the second number on the first output line is (33×323076926) mod (109+9)=661538468(33 \times 323076926) \bmod (10^9+9) = 661538468.

Examples1

  1. Example 1

    Input
    3
    
    3 3 1
    
    2 2 2
    
    4 5 3
    
    Expected output
    2 661538468
    1 1
    2 348111662