TRIOPT  Trigonometric optimization
Many problems arising in practical applications may be stated as optimization problems. Usually it is necessary to maximize or minimize so called criterion function taking into account some constraints.
Let’s consider a trigonometric optimization problem. It is necessary to maximize or to minimize criterion function F_{1}(x) + F_{2}(y) + F_{3}(z) with constraint x + y + z = S, where x, y, z – variables, S – parameter, x, y, z, S  natural numbers. Each of the functions F_{1}, F_{2} and F_{3} is a trigonometric function sin or cos.
You need to write a program which solves the trigonometric optimization problem.
Input
The first line of the input data contains integer T (1 ≤ T ≤ 65)  the number of testcases. Then the descriptions of T testcases follow.
The description of each testcase consists of 5 lines. The first line describes function F_{1} and contains either sin or cos. The second and the third lines describe functions F_{2} and F_{3} respectively and have the same format as the first line. Next, the fourth line contains either min or max. If the line contains min than it is necessary to minimize criterion function, otherwise it is necessary to maximize criterion function. Finally, the fifth line contains parameter S value (3 ≤ S ≤ 1 000 000).
Output
For each testcase you should output one line into the output data. This line should contain one real number – the found value of the criterion function. Absolute error of your answer must not exceed 10^{10}.
Example
Input: 1 sin cos sin max 10 Output: 2.7787651403
hide comments
Fahmi:
20110502 06:35:39
Last edit: 20120610 06:17:02 

tld:
20100706 12:42:43
oh,thank you!


:D:
20100706 11:15:43
I assumed that 0 is NOT natural in my solution and got AC. 

tld:
20100706 05:31:01
I want to know whether 0 is a natural number? 
Added by:  Ivan Metelsky 
Date:  20060427 
Time limit:  14.56s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  NEERC Western Subregion QF 2005 