Messege Story

All submissions for this problem are available.
Professor Gautam was trying to send a text message, and it took more than ten minutes to type a oneline message." Their placement of the letters is so messed up? he have to press '7' FOUR times to type an 's'"
In this problem, you are required to come up with the best letter placement of keys to minimize the number of key presses required to type a message. You will be given the number of keys, the maximum number of letters we can put on every key, the total number of letters in the alphabet, and the frequency of every letter in the message. Letters can be placed anywhere on the keys and in any order. Each letter can only appear on one key. Also, the alphabet can have more than 26 letters (it is not English).
For reference, the current phone keypad looks like this
key 2: abc key 3: def key 4: ghi key 5: jkl key 6: mno key 7: pqrs key 8: tuv key 9: wxyzThe first press of a key types the first letter. Each subsequent press advances to the next letter. For example, to type the word "snow", you need to press "7" four times, followed by "6" twice, followed by "6" three times, followed by "9" once. The total number of key presses is 10.
Input
 The first line in the input file contains the number of test cases N.Each case consists of two lines.
 On the first line we have the maximum number of letters to place on a key (P), the number of keys available (K) and the number of letters in our alphabet (L) all separated by single spaces.
 The second line has L nonnegative integers. Each number represents the frequency of a certain letter. The first number is how many times the first letter is used, the second number is how many times the second letter is used, and so on.
Output
For each case, you should output a no N indicating the number of keypad presses to type the message for the optimal layout.
Constrains
1 ≤ N ≤ 100
1 ≤ P ≤ 1000
1 ≤ K ≤ 1000
1 ≤ L ≤ 1000
Example
Input: 
2

Output 
47

Explanation
Example case 1.
In first case if we arrange alphabets like this,
key 1: L_{1}L_{2}
key 2: L_{3}L_{4}
key 3: L_{6}L_{5}
then he have to press keys 47 times.
where L_{i} denote i_{th} alphabet.
Author:  parac 
Tags  parac 
Date Added:  13092017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions