Let us fix an integer A. Consider a sequence f(n) which satisfies the following two conditions:
Given a prime p and an integer x (0≤x≤p), your task is to calculate ∣n:L≤n≤R, f(n)modp=x∣, that is, the number of indices n between L and R such that f(n)modp=x.
There are one or more test cases.
The first line of input contains an integer T, the number of test cases (1≤T≤42).
Each of the next T lines contains five integers A, p, x, L and R (0≤A<109, 2<p<109, 0≤x<p, 1≤L≤R≤1018). It is guaranteed that p is prime.
Print T lines, one for each test case, containing the answers to the problem.