Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

C24E08DE - EC08D Samurai Swords (E)

A craftsman and his apprentices are producing samurai swords. However at the end of its production each sword is tested and breaks with a probability p, independently of everything else.

The craftsman has an order of N swords which he has to produce in the next K months. At the end of that period, if he has not managed to produce K swords which passed the test, he has to pay a penalty of A gold coins for each sword missing. Surplus swords and swords that failed the test are not worth anything.

At the beginning of each month, the craftsman has to decide the number of swords they try to produce that month. Producing at least one sword has a fixed cost of C units plus an additional 1 unit per sword (regardless whether the sword passes the test or not).

Calculate the expected cost of the whole production if the craftsman follows an optimal plan to minimize the expected cost.

Input

The input files contain several test cases. The first line of the file contains a single integer, the number of test cases, T. The next T lines each describe a test case.

The test cases are described in lines containing the numbers p, N, K, A and C separated by spaces.

Output

Output a single integer (the expected cost rounded down) for every test case on a separate line.

This is the electronic variant of the problem. Read more here about submitting solutions!

Example

Input
2
0.1 1 1 5 1
0.9 1 1 5 1
Output
2
5

(In the first case, the expected value is 2.5 before rounding, in the second case it is 5.)


Added by:Jacek DÄ…browski
Date:2009-01-29
Time limit:0.200s-2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 ASM32 BASH BF C CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D ERL FORTRAN HASK ICON ICK JAVA JS-RHINO LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE
Resource:Challenge 24 2008 Electronic Contest

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.