public void solve() throws IOException {
    int t = nextInt();
    for (int i = 0; i < t; i++) {
      int d = nextInt();
      TreeMap<Integer, Integer> counts = new TreeMap<Integer, Integer>();
      for (int j = 0; j < d; j++) {
        int cakes = nextInt();
        if (!counts.containsKey(cakes)) {
          counts.put(cakes, 1);
        } else {
          counts.put(cakes, counts.get(cakes) + 1);
        }
      }
      
      int mintime = counts.lastKey();
      int time = 0, highest = mintime;
      while (highest > 3) {
        if (highest % 2 == 0) {
          if (!counts.containsKey(highest / 2)) {
            counts.put(highest / 2, counts.get(highest));
          } else {
            counts.put(highest / 2, counts.get(highest / 2) + counts.get(highest));
          }
        } else {
          if (!counts.containsKey(highest / 2 + 1)) {
            counts.put(highest / 2 + 1, counts.get(highest));
          } else {
            counts.put(highest / 2 + 1, counts.get(highest / 2 + 1) + counts.get(highest));
          }
        }
        if (!counts.containsKey(highest / 2)) {
          counts.put(highest / 2, counts.get(highest));
        } else {
          counts.put(highest / 2, counts.get(highest / 2) + counts.get(highest));
        }
        time = time + counts.get(highest);
        highest = counts.floorKey(highest - 1);
        mintime = Math.min(highest + time, mintime);
      }
      out.format("Case #%d: %d%n", i + 1, Math.min(mintime, time + highest));
    }
  }