#include <iostream>
using namespace std;

const int MAX = 100;

int main()
{
	int n, m;
	int icase=0;
	cin >> n >> m;
	while (n != 0 || m != 0) {
		icase++;
		cout << "Case " << icase << ":" << endl;
		if (n < 1 || n > MAX || m < 1 || m > MAX)
			cout << "ERROR: n, m out of bounds: " << n << ',' << m << endl;
		for(int i=0; i<n*m-1; i++) {
			int r; char d;
			cin >> r >> d;
			if (r < 1 || r > MAX)
				cout << "ERROR: move length out of bounds: " << r << endl;
			if (d != 'N' && d != 'S' && d != 'E' && d != 'W')
				cout << "ERROR: move direction illegal: " << d << endl;
		}

		cin >> n >> m;
	}
}

