import java.util.*;
public class Main {
public static Scanner scn = new Scanner(System.in);
public static void main(String args[]) {
tilingProb();
}
public static void tilingProb(){
int t = scn.nextInt();
while(t–>0){
long n = scn.nextLong();
long m = scn.nextLong();
System.out.println(TP(n,m));
}
}
public static long TP(long n, long m){
if(n>=1 && n<m) return 1; //only one way to place i.e vertically
if(n== m) return 2; // only 2 ways to place (all horizontal or all vertical)
long count = 0;
count = TP(n-1,m) + TP(n-m,m); //n-1 for all verticals and n-m for all horizontals placed consecutively beneath
return count;
}
}
