#include <iostream>
using namespace std;

const int MAXD = 100000000;
const int MAXC = 100;

int main()
{
	int l, s, d, n;
	int icase = 0;

	cin >> l >> s >> d >> n;
	while (l != 0 || s != 0 || d != 0 || n != 0) {
		icase++;
		cout << "Case " << icase << ":" << endl;
		if (l < 0 || l >= MAXD)
			cout << "ERROR: location out of range: " << l << endl;
		if (s < 0)
			cout << "ERROR: speed out of range: " << s << endl;
		if (d < 1 || d > MAXD)
			cout << "ERROR: destination out of range: " << n << endl;
		if (n < 0 || n > MAXC)
			cout << "ERROR: number of cars out of range: " << d << endl;
		if (l >= d)
			cout << "ERROR: location >= destination: " << l << ',' << d<< endl;
		for(int i=0; i<n; i++) {
			cin >> l >> s;
			if (l < 0 || l > d)
				cout << "ERROR: car " << (i+1) << " location out of bounds: " << l << endl;
			if (s < 0)
				cout << "ERROR: car " << (i+1) << " speed out of bounds: " << s << endl;
		}
		cin >> l >> s >> d >> n;
	}
}

