1 #include<stdio.h>
2 #include<string>
3 #include<iostream>
4 #include<math.h>
5 #include<time.h>
6 #include <stdlib.h>
7 using namespace std;
8 int Day_weak(int year,int month,int day)
9 {
10 if(month==1||month==2)
11 {
12 month +=12;
13 --year;
14 }
15 int week = -1;
16 week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1;
17 return week; // 输出-1为错误
18 }
19 int cmd(int n){
20 if((n%4==0&&n%100!=0)||(n%400==0)){
21 return 1;
22 }
23 return 0;
24 }
25 int main()
26 {
27 int t;
28 cin>>t;
29 while(t--){
30 int a,b,c;
31 int i;
32 scanf("%d-%d-%d",&a,&b,&c);
33 for(i=a+1;;i++)
34 {
35 if(cmd(i)==0&&b==2&&c==29) continue;
36 if(Day_weak(a,b,c)==Day_weak(i,b,c))
37 {
38 break;
39 }
40 }
41 cout<<i<<endl;
42 }
43 return 0;
44 }