http://acm.hdu.edu.cn/showproblem.php?pid=1076
/*
2011-9-10
author:BearFly1990
*/
package acm.hdu.tests;
import java.io.BufferedInputStream;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class HDU_1076 {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int t = in.nextInt();
//GregorianCalendar cal = new GregorianCalendar();
while(t-- > 0){
int year = in.nextInt();
int n = in.nextInt();
int count = 0;
int i = 0;
for(i = year; count < n; i++){
if(check(i))
count ++;
}
System.out.println(i-1);
}
}
public static boolean check(int y)
{
if((y%4==0&&y%100!=0)||(y%400==0))
return true;
else
return false;
}
}