#include <iostream>
#include <vector>
using namespace std;

const int MAXN = 9;

int main()
{
	int icase = 0;
	int n1, n2;
	cin >> n1 >> n2;
	while (n1 != 0) {
		icase++;
		cout << "Case " << icase <<":" << endl;
		if (n1 < 0 || n1 > 9)
			cout << "ERROR: n1 out of range" << endl;
		if (n2 < 0 || n2 > 9)
			cout << "ERROR: n2 out of range" << endl;
		long a1[MAXN], a2[MAXN];
		for(int i=0; i<n1; i++) {
			cin >> a1[i];
			if (a1[i] < -10 || a1[i] > 10)
				cout << "ERROR: partial quotient in first fraction out of range: " << a1[i] << endl;
			if (i != 0 && a1[i] <= 0)
				cout << "ERROR: partial quotient in first fraction out of range: " << a1[i] << endl;
		}
		for(int i=0; i<n2; i++) {
			cin >> a2[i];
			if (a2[i] < -10 || a2[i] > 10)
				cout << "ERROR: partial quotient in first fraction out of range: " << a2[i] << endl;
			if (i != 0 && a2[i] <= 0)
				cout << "ERROR: partial quotient in second fraction out of range: " << a2[i] << endl;
		}
		if (n2 == 1 && a2[0] == 0)
			cout << "ERROR: second fraction = 0" << endl;
		cin >> n1 >> n2;
	}
}


