Under construction

Still being built. Things may change

Squaring the Triangle

Time limit5sMemory limit256 MB

Summary
Given N vertices and edge probability p/q, find the expected square of the triangle count in a random graph, modulo 1e9+7, for T queries.
Level

Medium6 of 10

Topics
Math, Combinatorics, Probability, Number theory
Solved
No attempts yet

Problem

Wesley creates a graph GG with NN vertices. For each pair of vertices {u,v}\{u, v\}, an edge exists between uu and vv with probability pq\dfrac{p}{q}. The probabilities are independent of each other.

Let ∆(G)∆(G) denote the number of triangles in GG. A triangle is a set of 3 vertices connected by 3 edges.

Find the expected value of (∆(G))2(∆(G))^2.

Input

The first line contains an integer TT (1≤T≤1061 \le T \le 10^6), the number of cases. The next TT lines each contain integers NN, pp, qq (3≤N≤1063 \le N \le 10^6, 1≤p<q≤1061 \le p < q \le 10^6), separated by spaces.

Output

Output TT lines, one for each case. If the expected value for a case is PQ\dfrac{P}{Q} in lowest terms, output PQ−1 mod (109+7)PQ^{-1} \bmod (10^9 + 7). That is, output an integer RR with 0≤R<109+70 \le R < 10^9 + 7 such that P≡RQ(mod109+7)P \equiv RQ \pmod{10^9 + 7}.

Examples1

  1. Example 1

    Input
    2
    3 50 100
    7 8 9
    
    Expected output
    125000001
    655855196