Under construction

Still being built. Things may change

Sum of Powers 2

Time limit5sMemory limit512 MB

Summary
For each query with a, b, and d, compute the sum of k^d for k from a to b, modulo 10^9+7.
Level

Medium7 of 10

Topics
Math, Prefix sum, Number theory
Solved
No attempts yet

Problem

Write a program that answers the following queries over QQ lines.

  • aa bb dd : Print the value of (∑k=abkd)mod  (109+7)\left(\sum_{k=a}^{b} k^d\right)\mod\left(10^9+7\right).

Input

The first line contains the number of queries QQ.

Each of the next QQ lines contains one query from the problem, one per line.

Output

Print the answer to each query on its own line, in the same order as the input.

Constraints

All numbers in the input are integers.

1≤Q≤1061\leq Q\leq 10^6, 1≤a≤b≤1091\leq a\leq b\leq 10^9, 0≤d≤1050\leq d\leq 10^5

The sum of dd over all queries does not exceed 10610^6.

Examples1

  1. Example 1

    Input
    5
    1 100 1
    50 100 2
    1000 9999 3
    1000000000 1000000000 100000
    100000000 999999999 0
    
    Expected output
    5050
    297925
    507255250
    183133701
    900000000