## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Lost Arithmetic Progression Solution | Codeforces Problem Solution 2022

D. Lost Arithmetic Progression
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Long ago, you thought of two finite arithmetic progressions $A$ and $B$. Then you found out another sequence $C$ containing all elements common to both $A$ and $B$. It is not hard to see that $C$ is also a finite arithmetic progression. After many years, you forgot what $A$ was but remember $B$ and $C$. You are, for some reason, determined to find this lost arithmetic progression. Before you begin this eternal search, you want to know how many different finite arithmetic progressions exist which can be your lost progression $A$.

Two arithmetic progressions are considered different if they differ in their first term, common difference or number of terms.

It may be possible that there are infinitely many such progressions, in which case you won't even try to look for them! Print $-1$ in all such cases.

Even if there are finite number of them, the answer might be very large. So, you are only interested to find the answer modulo ${10}^{9}+7$.

Input

The first line of input contains a single integer $t$ ($1\le t\le 100$) denoting the number of testcases.

The first line of each testcase contains three integers $b$$q$ and $y$ ($-{10}^{9}\le b\le {10}^{9}$$1\le q\le {10}^{9}$$2\le y\le {10}^{9}$) denoting the first term, common difference and number of terms of $B$ respectively.

The second line of each testcase contains three integers $c$$r$ and $z$ ($-{10}^{9}\le c\le {10}^{9}$$1\le r\le {10}^{9}$$2\le z\le {10}^{9}$) denoting the first term, common difference and number of terms of $C$ respectively.

Output

For each testcase, print a single line containing a single integer.

If there are infinitely many finite arithmetic progressions which could be your lost progression $A$, print $-1$.

Otherwise, print the number of finite arithmetic progressions which could be your lost progression $A$ modulo ${10}^{9}+7$. In particular, if there are no such finite arithmetic progressions, print $0$.