#include 
#include 
using namespace std;
bool isleep(int year);
int main(){
int I1;
int I2;
int I3;
	for(;;){
		cin >> I1 >> I2 >> I3;
		
		if(I1 == 0 && I2 == 0 && I3 == 0){
			break;
		}
		if(I3 < 0 || I2 < 0 || I1 < 0){
			cout  <<  "Invalid 1"  << endl;
			continue;
		}
	
		if(I1 > 31){
			cout <<  "Invalid 2"  << endl;
			continue;
		}
	
		if(I2  > 12){
			cout <<  "Invalid"  << endl;
			continue;
		}
	
		if(isleep(I3)){
			// leap
			if (I1 > 29 && I2 == 2){
				cout <<  "Invalid 3"  << endl;
				continue;}
		}else{
			// no leap
			if (I1 > 28  && I2 == 2){
				cout <<  "Invalid 4"  << endl;
				continue;}
		}
		if(I1 == 31  && (I2 == 4  || I2 == 9  || I2  == 11 || I2 == 6)){
			cout <<  "Invalid 5"  << endl;
			continue;}
	
		cout  <<  "Valid"  << endl;
	}
return 0;
}

bool  isleep(int year){

	if  (year % 4)  
		return false;

	if  (year % 100){
		return true;
	}else{
		if  (year % 400)
			return false;
		else
			return true;
	}
}

    Source: geocities.com/twomcm/prog_code

               ( geocities.com/twomcm)