Pia's Party

No attempts yetTime limit1sMemory limit128 MB

Problem

Pia wants to set up the audio system for her birthday party. The party will take place on a circular area, because Pia believes a circle is the most beautiful two-dimensional shape. Pia has four loudspeakers that she can place on certain points along the circle's circumference. From her extensive party experience she knows that people will only dance in the region enclosed by the four loudspeakers. Because she wants the dance floor to be as large as possible, she wants to maximize the area of the quadrilateral defined by the four loudspeakers. Can you help Pia?

You are given a circle of diameter dd with nn points equally spaced around its circumference. The points are numbered in order around the circle as 0,1,2,,n10, 1, 2, \dots, n-1. Of these nn points, cc are suitable for placing loudspeakers. These points are given by the generator function (gk)modn(g \cdot k) \bmod n for k{0,1,2,,c1}k \in \{0, 1, 2, \dots, c-1\}. Given the integers dd, nn, cc, and gg, compute the largest area that can be formed by placing four loudspeakers on suitable points.

Input

The first line contains the number of scenarios.

Each scenario consists of a single line containing four space-separated integers, whose meanings are, in order:

  • the diameter dd of the circle (1d10001 \le d \le 1000);
  • the number nn of points on the circle (4n1094 \le n \le 10^9);
  • the number cc of points suitable for loudspeakers (4c10004 \le c \le 1000 and cnc \le n);
  • the number gg for the generator function (1gn1 \le g \le n), which is relatively prime to nn (that is, they share no common divisor greater than 1).

Output

For each scenario, first print a line of the form Scenario #i:, where ii is the scenario number starting from 1.

Then print a single line with the maximum area Pia can achieve for her dance floor, rounded to six decimal places. Separate two consecutive scenarios with a single blank line.