Sanggeun built a hashing function that maps an integer to a value in 0 through m−1:
h(y)=(a⋅y+b)modm
Given integers x, n, c, and d, write a program that counts how many of the hash values
h(x), h(x+1), …, h(x+n)
fall within the interval [c,d].
The first line contains the number of test cases t (1≤t≤105).
Each of the next t lines contains the integers a, b, x, n, c, d, m separated by spaces.
Every number in the input is a non-negative integer.
For each test case, output on its own line the number of indices i (0≤i≤n) satisfying c≤(a⋅(x+i)+b)modm≤d.