Under construction

Still being built. Things may change

Drawing lots

Time limit2sMemory limit512 MB

Summary
Compute the expected number of draws until a blue lot has been drawn K times, where red lots are removed and green and blue lots are returned.
Level

Hard9 of 10

Topics
Probability, Math, Dynamic programming
Solved
No attempts yet

Problem

He draws lots whenever he has time to spare. Drawing them with no rules attached got boring, so he settled on rules that depend on the color of the lot he draws.

He has RR lots with a red tip, GG lots with a green tip, and BB lots with a blue tip. He puts every lot into a box with the colored end hidden, mixes the box well, and draws one lot at a time. He mixes the box thoroughly every time, so every lot still in the box is equally likely to be drawn. He acts on the color of the lot he drew as follows.

  1. If he draws a red lot, he throws that lot away.
  2. If he draws a green lot, he puts it back into the box and mixes the box.
  3. If he draws a blue lot, he puts it back into the box and mixes the box. Once he has drawn a blue lot KK times, he stops drawing and goes to sleep.

Write a program that computes the expected number of lots he draws before he goes to sleep.

Input

The first line contains the number of test cases TT (1≤T≤1031 \le T \le 10^3).

Each test case is one line holding the number of red lots RR, the number of green lots GG, the number of blue lots BB, and the number of blue draws KK that sends him to sleep, separated by spaces. All four numbers are integers between 11 and 10910^9.

Output

For each test case, print the expected number of lots he draws before he goes to sleep on its own line.

When the expected value is written as the irreducible fraction a/ba/b, print the remainder of a×b−1a \times b^{-1} divided by 1,000,000,007. Here b−1b^{-1} is the multiplicative inverse of bb modulo 1,000,000,007. An answer exists for every input.

Hint

For R=1R = 1, G=1G = 1, B=1B = 1, K=1K = 1 the expected value is 5/25/2. The inverse of 22 modulo 1,000,000,007 is 500000004500000004, so print the remainder of 5×5000000045 \times 500000004 divided by 1,000,000,007, which is 500000006500000006.

Examples2

  1. Example 1

    Input
    4
    1 1 1 1
    1 2 3 4
    1000 1000 1 1000
    50000 50000 50000 10000000
    
    Expected output
    500000006
    569010428
    490804548
    595034885
    
  2. Example 2

    Input
    4
    9 9 9 1
    9 9 9 2
    9 9 9 4
    9 9 9 1000
    
    Expected output
    300000005
    470000009
    700700016
    814176661