TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Every pizza has its own product identification number, which is generated as N digits on base K. That is, each digit can be any number between 0 and K-1. Some magic pizza, flavor of tomatoes, need special IDs. We say an ID is special if it contains "514" as its subsequence. For example, 50214 is such a special ID but 50216 is not. If each ID is generated randomly with equal probability given N and K, what is the probability that a special ID shows up?


Note that, a digit 51 is not counted as 5, and/or 1. So if an ID has the first digit 51, the second digit 51 and the third digit 4, this ID is NOT special.

Input Format

The first line of the input file contains an integer T (1<= T<= 100) indicating the number of test cases.


For each test case, there are two integers N, K (2<= N, K<= 100) separated by a space.

Output Format

For each test case, output the probability in one line with at least 6 digits after the decimal point.

Sample Input 1

3
5 10
6 10
7 10

Sample Output 1

0.008560000
0.015850000
0.025691500

Hints

Info: 本題輸出為浮點數,絕對或相對誤差 1e-6 以下視為正確

Problem Source

Migrated from old NTUJ.

Tmt, Ferng

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 200