Squaring the Triangle
시간 제한5초메모리 제한256 MB
각 간선이 독립적으로 확률 p/q로 존재하는 N개 정점의 무작위 그래프에서 삼각형 개수의 제곱의 기댓값을 1e9+7로 나눈 나머지를 구한다.
문제
Wesley creates a graph that contains vertices. For each pair of vertices , there is a probability of that an edge exists between and . The probabilities are independent of each other.
Let denote the number of triangles in . A triangle is a set of vertices that are connected by edges.
Please help Wesley find the expected value of .
입력
Line contains integer (), the number of cases. lines follow. The th line contains integers , , (, ), separated by spaces.
출력
Output lines, one line for each case. Suppose the answer to the th case is , in lowest terms. Output . That is, output a number such that and .