public void solve() throws IOException {
    int T = nextInt();
    for (int t = 1; t <= T; t++) {
      String S = nextLine();
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < S.length(); i++) {
        if (i == 0 || Character.compare(S.charAt(i), sb.charAt(0)) < 0) {
          sb.append(S.charAt(i));
        } else {
          sb.insert(0, S.charAt(i));
        }
      }
      out.format("Case #%d: %s\n", t, sb.toString());
    }
  }