P14475 [HackerEarth] Pick a random financial transaction from the ledger of a typical business and there is about a 30% chance that the first non-zero digit of the amount of money involved is a 1. This count
普及-
题目描述

Pick a random financial transaction from the ledger of a typical business and there is about a 30% chance that the first non-zero digit of the amount of money involved is a 1. This counter-intuitive fact is a result of Benford's Law, discovered by astronomer Simon Newcomb in the late 1800's and rediscovered by physicist Frank Benford in the early 1900's. They found that real world data are not evenly distributed. Instead, given a random number related to some natural or social phenomenon satisfying certain conditions, the probability that the first non-zero digit of the number is D is log10(1 + 1/D).
Increasingly, financial auditors are using Benford's Law to detect possible fraud. Given a record of the financial transactions of a company, if some leading digit appears with a frequency that significantly differs from that predicted by Benford's Law, it is a signal that those transactions deserve a closer look.
Return the smallest digit that appears as the first non-zero digit of numbers in transactions with a frequency that is at least threshold times more or less than its expected frequency (e.g., more than
three times the expected frequency or less than one-third the expected frequency when threshold=3). If no such digit exists, return -1.

First line contains number of test cases.
In every test case first line contains n (Number of transactions)
Then n space separated integers follows.
Then the threshold value is given.
1 ≤ t ≤ 25
1 ≤ n ≤ 50
1 ≤ elements ≤ 999999999
2 ≤ threshold ≤ 10

SAMPLE INPUT
1
20
5236 7290 200 1907 3336 9182 17 4209 8746 7932 6375 909 2189 3977 2389 2500 1239 3448 6380 4812
2

SAMPLE OUTPUT
1

Explanation

The following chart gives the actual frequency of each leading digit, and its expected frequency according to Benford's law.
digit | 1 2 3 4 5 6 7 8 9
---------|---------------------------------------------
actual | 3 4 3 2 1 2 2 1 2
expected | 6.02 3.52 2.50 1.94 1.58 1.34 1.16 1.02 0.92
Assuming a threshold of 2, there are two digits that are questionable: the leading digit 1 appears less than half as often as expected and the leading digit 9 appears more than twice as often as expected. Since 1 is smaller than 9, the answer is 1.

输入格式

见题面

输出格式

见题面

样例输入
10 20 5236 7290 200 1907 3336 9182 17 4209 8746 7932 6375 909 2189 3977 2389 2500 1239 3448 6380 4812 2 10 1 10 100 2 20 200 2000 3 30 300 2 12 9 87 765 6543 54321 43219 321987 21987 1987 345 234 123 2 15 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 8 13 987 234 1234 234873487 876 234562 17 7575734 5555 4210 678234 3999 8123 3 30 168249 128764 274843 480487 6470 321163 914970 651946 860681 651156 533305 97811 948843 357358 312413 255070 74193 28869 793437 592639 25154 554199 458379 585723 957071 620787 618315 999088 992120 660875 5 30 929238 225022 368132 419489 406037 476829 454825 792981 873000 566777 925392 448354 270943 717454 441466 943277 981218 825975 529528 884725 366158 409775 286906 97902 136183 644910 660556 268189 344640 310889 9 30 87686 300702 161999 917426 475725 725295 312782 410472 237840 75515 674516 391965 562072 154635 359049 934178 555142 159623 623961 864710 617694 108332 828539 602937 170762 543943 461252 582121 176235 789195 3 40 935189 872499 767283 621491 284705 445848 187047 410621 215923 116325 926201 764755 175689 982944 906067 427226 227093 691445 937981 182991 11663 916071 852174 503223 601235 543188 21146 36881 37372 384399 10735 386812 527127 99382 108651 851071 396242 892414 778132 784572 2 37 2 8 2 2 138836868 4 12 157 19 3 102 879 5 5 35 4 4 19 666 24 123 7 937 209 6 7 2 3 100 3 4 3 4 111 4 2 4 4
样例输出
5 6 8 -1 -1 4 -1 -1 6 -1 -1 -1 8 2 2 1 8 2 9 1 -1 -1