import java.util.*;
public class Main
{
static int count(int n,int m)
{
int ways[] = new int[n + 1];
ways[0] = 0;
int i;
for (i = 1; i <= n; i++)
{
if (i > m)
ways[i] = ways[i - 1] + ways[i - m];
else if (i < m || i == 1)
ways[i] = 1;
else
ways[i] = 2;
}
return ways[n];
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
for(int i=0;i<test;i++)
{
int n=sc.nextInt();
int m=sc.nextInt();
System.out.print(count(n,m));
}
}
}