/* Problem 1--Recording a Tape
   There was nothing tricky about this, just read the input and divide
   the list in the middle. */

import java.io.*;
import java.util.*;

public class prob1 {

 public static BufferedReader in;
 public static PrintStream out;
 public static StringTokenizer st;

 public static void main (String[] args) throws Exception {

  in = new BufferedReader (new FileReader ("prob1.in"));
  out = new PrintStream (new FileOutputStream ("prob1.out"));
  while (true) {
   int[] Durations = new int[10];//Read in the tapes
   String s = in.readLine ();
   if (s==null) break;
   int ct = 0;
   st = new StringTokenizer (s);
   while (st.hasMoreTokens())
    Durations[ct++] = Integer.parseInt (st.nextToken());
   int[] Sec = new int[100];
   int sct = 0, tot = 0;
   while (true) { //Read in the songs, convert hem to seconds and store
    s = in.readLine ();
    if (s.equals ("%")) break;
    st = new StringTokenizer (s);
    String t = st.nextToken();
    int m = Integer.parseInt (t.substring(0,t.length()-1));
    t = st.nextToken ();
    m = 60*m + Integer.parseInt (t.substring(0,t.length()-1));
    Sec[sct++] = m;
    tot += m;
   }
   int mindiff = tot, mini = -1, half1 = 0, half2 = tot;
   for (int i=0; i < sct; i++) { //Go through and find the best place
    half1 += Sec[i]; half2 -= Sec[i]; //to break them up.
    if (Math.abs (half1-half2) < mindiff) {
     mindiff = Math.abs (half1-half2); mini = i;
    }
   }
   int totdur = (tot+mindiff)/2; //Minimum length of the tape
   int max = -1;
   for (int i = 0; i < ct; i++) //Find the smallest acceptable one
    if (30*Durations[i] >= totdur && (max==-1 || Durations[i] < max))
     max = Durations[i];
   out.println (max); //Print the information
   out.println ("Side A");
   for (int i=0; i <= mini; i++)
    out.println (Sec[i]/60+"m "+Sec[i]%60+"s");
   out.println ("Side B");
   for (int i=mini+1; i < sct; i++)
    out.println (Sec[i]/60+"m "+Sec[i]%60+"s");
   out.println ("%");
  }
 }
}
