SP827 TRIOPT - Trigonometric optimization
Description
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 Format
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 Format
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} $** .