The first line contains the number of scenarios.
Every scenario consists of a single line containing four integers separated by a space. The meaning of these numbers are in order:
- The diameter d of the circle (1 <= d <= 1000).
- The number n of points on the circle (4 <= n <= 109).
- The number c of suitable points for the loudspeakers (4 <= c <= 1000 and c <= n).
- The number g for the generator function (1 <= g <= n) which will be relatively prime to n (e.g. they do not have a common divisor greater than 1).