import java.util.*; public class ny08e { public class Pair { ArrayList al; double cost; public Pair(ArrayList a, double c) { cost = c; al = a; } public int hashCode() { String s = ""; for(Integer i : al){ s += i+","; } s += "--"+cost; return s.hashCode(); } } double[] freqs = new double[26]; HashMap cache = new HashMap(); public void solve(int n) { cache = new HashMap(); freqs = new double[26]; int k = in.nextInt(); in.nextLine(); String[] s = (in.nextLine() + " " + in.nextLine()).split("\\s+"); double tot = 0; for(int i = 0; i < s.length; i++) { freqs[i] = Double.parseDouble(s[i]);// / 100.0; System.out.println((char)(i + 65) + ": "+ freqs[i]); tot += freqs[i]; } Pair p = r(0, k-1); String finStr = ""; int cnt = p.al.size()-1; int cur = p.al.get(cnt); double keys = 1; HashSet hs = new HashSet(p.al); double cost = 0; for(int i = 0; i < freqs.length; i++) { if(hs.contains(i)) { finStr += " "; cnt--; keys = 1; if(cnt > 0) cur = p.al.get(cnt); } finStr += (char)(i + 65) + ""; cost += freqs[i] * keys; keys++; } System.out.println(n + " " + dblToString(p.cost / 100.0, 3) + " " + finStr ); //+ " -- " +k); } public Pair r(int s, int k) { if(cache.containsKey(s+","+k)) return cache.get(s+","+k); if(k == 0) { double n = 0; int cnt = 1; for(int i = s; i < freqs.length; i++) { n += cnt * freqs[i]; cnt++; } Pair p = new Pair(new ArrayList(), n); cache.put(s+","+k, p); return p; } Pair min = new Pair(new ArrayList(), -1); double selfCost = 0; double cnt = 1; for(int i = s; i < (freqs.length-k); i++){ selfCost += cnt * freqs[i]; cnt++; Pair p = r(i+1, k-1); if(min.cost == -1 || (p.cost+selfCost) < min.cost) { min.cost = selfCost + p.cost; min.al = cloneAndNew(p.al, i+1); } } cache.put(s+","+k, min); return min; } public String dblToString(double d, int p) { int x = (int)Math.round(d*Math.pow(10, p)); double x2 = x * 1.0 / Math.pow(10,p); String s = Double.toString(x2); String s2[] = s.split("\\."); while(s2[1].length() < p) { s2[1] += "0"; } return s2[0]+"."+s2[1]; } public ArrayList cloneAndNew(ArrayList a, int n){ ArrayList r = new ArrayList(); for(int i = 0; i < a.size(); i++){ r.add(i, a.get(i)); } r.add( r.size(), n ); return r; } static Scanner in = new Scanner(System.in); public static void main(String[] args) { int n = in.nextInt(); for(int i = 0; i < n; i++) { ny08e r = new ny08e(); r.solve(i+1); } } }