aa
#include <iostream>
#include <string>
using namespace std;
int YY1[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int YY2[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int id1[17] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
char checkCode[11] = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' };
class CDate {
private:
int year;
int month;
int day;
public:
CDate() {};
CDate(int, int, int);
void datain() {
cin >> year >> month >> day;
}
int getyear() {
return year;
}
int getmonth() {
return month;
}
int getday() {
return day;
}
bool check() {
if (year > 2017 || year == 2017 && month > 5 || year == 2017 && month == 5 && day > 10)
return false;
if (isLeap())
{
if (YY1[month - 1] < day)
return false;
}
else {
if (YY2[month - 1] < day)
return false;
}
return true;
}
string tostring() {
string a = to_string(year);
string b = to_string(month);
string c = to_string(day);
if (b.length() == 1)
b.insert(b.begin(), '0');
if (c.length() == 1)
c.insert(c.begin(), '0');
a.append(b);
a.append(c);
return a;
}
bool isLeap() {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
return true;
else
return false;
}
void print() {
cout << year << "年" << month << "月" << day << "日 ";
}
};
class COldID {
protected:
string pid15;
string p_name; //15位身份证号码,姓名
CDate birthday; //出生日期
public:
COldID() {}
void datain() {
cin >> p_name;
birthday.datain();
cin >> pid15;
}
bool check() {
cout << p_name << endl;
if (!birthday.check())
return false;
if (pid15.length() != 15)
return false;
for (int i = 0; i < 15; i++) {
if (!isdigit(pid15[i]))
return false;
}
return true;
}
void print() {}
~COldID() {}
};
class CNewID : public COldID
{
private:
string pid18;
CDate issueday;
int vyear;
public:
CNewID() {
COldID::datain();
cin >> pid18;
issueday.datain();
cin >> vyear;
}
bool check() {
if (!COldID::check())
return false;
if (pid18.substr(0, 5) != pid15.substr(0, 5) || pid18.substr(8, 8) != pid15.substr(6, 8))
return false;
if (pid18.find(birthday.tostring()) == -1)
return false;
if (!issueday.check())
return false;
if (pid18.length() != 18)
return false;
int temp = 0;
for (int i = 0; i < 17; i++) {
temp += (pid18[i] - '0') * id1[i];
}
temp %= 11;
if (checkCode[temp] != pid18[17])
return false;
if (issueday.getyear() + vyear < 2017 || issueday.getyear() + vyear == 2017 && issueday.getmonth() > 5 || issueday.getyear() + vyear == 2017 && issueday.getmonth() == 5 && issueday.getday() > 10)
return false;
return true;
}
void print() {
COldID::print();
cout << pid18 << " ";
issueday.print();
if (vyear < 100)
cout << vyear << "年" << endl;
else cout << "长期" << endl;
}
};
int main() {
int t;
cin >> t;
while (t--) {
CNewID nsfz;
if (nsfz.check())
{
nsfz.print();
}
else
{
cout << "illegal id" << endl;
}
}
}