SP30973 ADATOMAT - Ada and Tomato

Description

Ada the Ladybug grows tomatoes. She has a very long furrow full of them. At the day of harvest, she picks all tomatoes, **sorts** them by size, index them (from 1) and sell them for price of "**size × index**". How much money will she make, if she sells all of them? As the nature is very beautiful (and Ada is great mathematician), she found the pattern for sizes of tomatoes. The patern works in (hopefully well known) way: Let us have tomato of size **X $ _{i} $** , then **X $ _{i+1} $** will be counted as **X $ _{i+1} $ =X $ _{i} $ \*a+b mod M**. **M** (modulo) is equal to **10 $ ^{9} $ +7** (1000000007).

Input Format

The first line contains **1 , the number of test-cases.** Each test-case contains four numbers **N, a, b, X $ _{1} $** : **1 , the number of tomatoes.** **0 - described above (X $ _{1} $ is the size of first tomato).** Sum of **N** over all test-cases will not exceed **5\*10 $ ^{7} $** .

Output Format

For each test-case output the sum of all prices modulo **10 $ ^{9} $ +7**.