#include <iostream.h>
#include <stdio.h>
#include <string.h>


struct horas {
       int horas;
       int minutos;
       int horaf;
       int minutof;
       };


int main() {
int casos;

char texto[255];
    
int a,b,c,d;
char t,q;

int prueba=1;
int h,m;


while(cin >> casos) {
      
      horas temp[casos+2];
      horas var;
      int difmin;
      int max=0;
      for(int i=1; i <= casos; i++) {
              
         cin >> temp[i].horas;
         cin >> t;
         cin >> temp[i].minutos;
         cin >> temp[i].horaf;
         cin >> q;
         cin >> temp[i].minutof;     
         cin.getline(texto,255);
      } 
	temp[0].horaf= 10;
	temp[0].minutof=0;
	//de 10 a la primera cita 
      temp[casos+1].horas = 18;
      temp[casos+1].minutos = 0;  
      //ordenar horas
      for(int i = 1; i <= casos; i++){
            for(int j = 1; j <= casos-1; j++){
                  if(temp[j+1].horas < temp[j].horas){
                    var = temp[j];
                    temp[j] = temp[j+1];
                    temp[j+1] = var;
                  }
                  else if((temp[j+1].horas == temp[j].horas) && (temp[j+1].minutos < temp[j].minutos)){
                        var = temp[j];
                        temp[j] = temp[j+1];
                        temp[j+1] = var;
                       }
            }
      }
     // for(int i = 1; i <= casos+1; i++){
       //       cout << temp[i].horas << ":"<< temp[i].minutos<<"\n";
      //}
      
      for (int i=0; i <= casos; i++) {
               difmin= (temp[i+1].horas - temp[i].horaf)*60;
              difmin= difmin + (temp[i+1].minutos - temp[i].minutof);
              
              if (max < difmin) { 
                  max = difmin; 
                  h= temp[i].horaf;
                  m=temp[i].minutof;
              }
      } 
      
      if (max < 60) { 
              
              if (m<10) printf("Day #%i: the longest nap starts at %i:0%i and will last for %i minutes.\n",prueba,h,m,max); 
              else printf("Day #%i: the longest nap starts at %i:%i and will last for %i minutes.\n",prueba,h,m,max);
      
      }
      else {
           int tmp1= max/60;
           int tmp2=max%60;
          
          
          if (m<10)
           printf("Day #%i: the longest nap starts at %i:0%i and will last for %i hours and %i minutes.\n",prueba,h,m,tmp1,tmp2);
           else printf("Day #%i: the longest nap starts at %i:%i and will last for %i hours and %i minutes.\n",prueba,h,m,tmp1,tmp2);
                      
           }
           
         prueba++;   

}


return 0;
}
