#include<stdio.h>
int main()
{
	int n,i,a,b,d,e,f,g;
	int lunchsum,dinnersum,midnightsum,lunchss,dinnerss,midnightss;
	char c;
	while(scanf("%d",&n)&&(n!=0))
	{ 
	
		lunchsum=0;
		dinnersum=0;
		midnightsum=0;
		lunchss=0;
			dinnerss=0;
		midnightss=0;
		for(i=0;i<n;i++)
		{
			scanf("%d%c%d%d",&a,&c,&b,&d);
			if(a>=11&&a<=14)
			{
				lunchsum++;
				if((d-b)<=8&&(d-b)>=0)
					lunchss++;
				else if((d-b)<0)
				{
					if((d+60-b)<=8&&(a!=14))
						lunchss++;
				}
			}
			else if(a>=18&&a<=20)
		          
			{
				dinnersum++;
				if((d-b)<=8&&(d-b)>=0)
					dinnerss++;
				else if((d-b)<0)
				{
					if((d+60-b)<=8&&(a!=20))
						dinnerss++;
				}
			}
			else if((a>=21&&a<=23)||a<=1&&a>=0