#include<iostream>
#include<vector>
#include<cstdlib>

using namespace std;

class CTime{
	int h,m;
public:

	CTime():h(0),m(0){}
	CTime(int n):h(n/100),m(n%100){}

	void Set(int n){h=n/100;m=n%100;}
	void SetByMinutes(int m){this->h=m/60;this->m=m%60;}
	int minutes()const{return 60*h+m;}
	int time()const{return 100*h+m;}

	CTime operator+(int minute)const{
		CTime ret;
		ret.SetByMinutes( this->minutes() + minute );
		return ret;
	}
	CTime operator-(const CTime &t)const{
		CTime ret;
		int n = 0;
		if( t.h > h ){
			n += 60 * (t.h - h);
			n += (t.m - m);
		}else if( t.h == h ){
			n += abs(m - t.m);
		}else{
			n += 60 * (h - t.h);
			n += (m - t.m);
		}
		ret.SetByMinutes( n );
		return ret;
	}

	bool operator>(const CTime &t)const{return this->time() > t.time();}
	bool operator>=(const CTime &t)const{return this->time() >= t.time();}
};

typedef vector< pair<CTime, int> > Channel;
typedef vector< Channel > Channels;

int main(void){
	while(true){
		int max_duration = 0;
		int sum_duration = 0;
		int n, p, q;
		CTime st, ed, curTime;
		Channels vChannels;

		cin >> n >> p >> q;
		if( !(n || p || q) )
			break;

		st.Set( p );
		curTime.Set( p );
		ed.Set( q );

		if( n == 0 ){
			cout << (ed-st).minutes() << endl;
			continue;
		}

		for(int i = 0; i < n; ++i){
			int e,s,k;
			CTime ce,cs;

			cin >> k;
			Channel tmp;
			vChannels.push_back( tmp );

			if( k == 0 ){
				vChannels[i].push_back( make_pair(st, (ed - st).minutes()) );
				continue;
			}
			
			cin >> s;
			cs.Set( s );

			if( cs > st ){
				vChannels[i].push_back( make_pair(st, (cs-st).minutes() ) );
			}

			for(int j = 0; j < k; ++j){
				if( j < k - 1 ){
					cin >> e >> s;
					cs.Set( s );
					ce.Set( e );
				}else{
					cin >> e;
					cs.Set( q );
					ce.Set( e );
				}
				if( (cs-ce).minutes() > 0 )
					vChannels[i].push_back( make_pair(e,(cs-ce).minutes() ));
			}
		}

		/*
		for(unsigned int i = 0; i < vChannels.size(); ++i){
			cout << i + 1 << "Ch. programs-> ";
			for(unsigned int j = 0; j < vChannels[i].size(); ++j){
				cout << vChannels[i][j].first.time() << " " << vChannels[i][j].second << "|";
			}
			cout << endl;
		}
		*/

		while( true ){
			int curChannel = -1;
			int curChannelIdx = -1;
			int max_sub_duration = 0;

			for(unsigned int i = 0; i < vChannels.size(); ++i){
				for(unsigned int j = 0; j < vChannels[i].size(); ++j){
					if( curTime >= vChannels[i][j].first &&
						vChannels[i][j].first + vChannels[i][j].second > curTime &&
						vChannels[i][j].second+(curTime - vChannels[i][j].first).minutes() > max_sub_duration )
					{
						max_sub_duration = vChannels[i][j].second - (curTime - vChannels[i][j].first).minutes();
						curChannel = i;
						curChannelIdx = j;
					}
				}
			}

			if( curChannel < 0 ){
				int minBoringTime = 1 << 22;

				max_duration = max( max_duration, sum_duration );
				sum_duration = 0;
				for(unsigned int i = 0; i < vChannels.size(); ++i){
					for(unsigned int j = 0; j < vChannels[i].size(); ++j){
						if( vChannels[i][j].first > curTime &&
							(vChannels[i][j].first - curTime).minutes() < minBoringTime )
						{
							minBoringTime = (vChannels[i][j].first - curTime).minutes();
							curChannel = i;
							curChannelIdx = j;
						}
					}
				}

				/* TV time is end */
				if( curChannel < 0 )
					break;

				curTime = vChannels[curChannel][curChannelIdx].first;
			}else{
				// cout << curChannel << endl;
				sum_duration += max_sub_duration;
				curTime = vChannels[curChannel][curChannelIdx].first + 
					vChannels[curChannel][curChannelIdx].second;
			}
		}
		cout << max_duration << endl;
	}
	return 0;
}

Measured memory_bytes: 0