package sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		ArrayList<Integer> a=new ArrayList<Integer>(n);
		//System.out.println("mn");
		for(int i=0;i<n;i++)
		{
			int t=sc.nextInt();
			a.add(t);
		}
		//System.out.println("lm");
		Collections.sort(a);
	int ans=0;
		for(int i=0;i<a.size();i++)
	        ans+=(((a.get(i)*a.get(n-i-1))%10007));
		System.out.println(ans%10007);
	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		ArrayList<Integer> a=new ArrayList<Integer>(n);
		//System.out.println("mn");
		for(int i=0;i<n;i++)
		{
			int t=sc.nextInt();
			a.add(t);
		}
		//System.out.println("lm");
		Collections.sort(a);
	int ans=0;
		for(int i=0;i<a.size();i++)
	        ans+=(((a.get(i)*a.get(n-i-1))));
		System.out.println(ans%10007);
	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		ArrayList<Integer> a=new ArrayList<Integer>(n);
		//System.out.println("mn");
		for(int i=0;i<n;i++)
		{
			int t=sc.nextInt();
			a.add(t);
		}
		//System.out.println("lm");
		Collections.sort(a);
	int ans=0;
		for(int i=0;i<a.size();i++)
	        ans+=(((a.get(i)*a.get(n-i-1))%10007));
		System.out.println(ans);
	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		long n=sc.nextLong();
		ArrayList<Long> a=new ArrayList<Long>();
		//System.out.println("mn");
		for(long i=0;i<n;i++)
		{
			long t=sc.nextInt();
			a.add(t);
		}
		//System.out.println("lm");
		Collections.sort(a);
	long ans=0;
		for(long i=0;i<a.size();i++)
	        ans+=(((a.get((int) i)*a.get((int) (n-i-1)))%10007));
		System.out.println(ans%10007);
	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		ArrayList<Integer> a=new ArrayList<Integer>(n);
		//System.out.println("mn");
		for(int i=0;i<n;i++)
		{
			int t=sc.nextInt();
			a.add(t);
		}
		//System.out.println("lm");
		Collections.sort(a);
	int ans=0;
		for(int i=0;i<a.size();i++)
	        ans+=(((a.get(i)*a.get(n-i-1))%10007));
		System.out.println(ans%10007);
	}

}


import java.io.*;
import java.util.*;

public class A {
	public static void main(String[] args) throws Exception {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);

		int MOD = 10007;

		int n = Integer.parseInt(f.readLine());
		long[] stu = new long[n], dif = new long[n];
		for(int i = 0; i < n; i++) {
			int num = Integer.parseInt(f.readLine());
			stu[i] = num; dif[i] = num;
		}
		Arrays.sort(dif);
		Arrays.sort(stu);
		int idx = n-1;
		long ans = 0;
		for(int i = 0; i < n; i++) {
			long add = stu[i] * dif[idx];
			idx--;
			ans += add;
			ans %= MOD;
		}
		System.out.println(ans);
	}
}


import java.io.*;
import java.util.*;

public class A {
	public static void main(String[] args) throws Exception {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);

		int MOD = 10007;

		int n = Integer.parseInt(f.readLine());
		int[] stu = new int[n], dif = new int[n];
		for(int i = 0; i < n; i++) {
			int num = Integer.parseInt(f.readLine());
			stu[i] = num; dif[i] = num;
		}
		Arrays.sort(dif);
		Arrays.sort(stu);
		int idx = n-1;
		long ans = 0;
		for(int i = 0; i < n; i++) {
			long add = stu[i] * dif[idx];
			idx--;
			ans += add;
			ans %= MOD;
		}
		System.out.println(ans);
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Potions {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));

		// Start writing your solution here.
		// -------------------------------------

		int n = sc.nextInt(); // read input as integer
		int[] students = new int[n];
		for (int i = 0; i < n; i++) {
			students[i] = sc.nextInt();
		}
		Arrays.sort(students);
		int[] tasks = new int[n];
		for (int i = 0; i < n; i++) {
			tasks[i] = students[n - (i + 1)];
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += ((students[i] % 10007) * (tasks[i] % 10007)) % 10007;
		}

		/*
		 * long k = sc.nextLong(); // read input as long
		 * double d = sc.nextDouble(); // read input as double
		 * String str = sc.next(); // read input as String
		 * String s = sc.nextLine(); // read whole line as String
		 *
		 * int result = 3*n;
		 */
		out.println(sum % 10007); // print via PrintWriter

		// Stop writing your solution here.
		// -------------------------------------
		out.close();
	}

	// -----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	// --------------------------------------------------------
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Created by abhimanyu-singh on 9/11/16.
 */
public class PotionsHome {
    public static void main(String args[])throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        int arr[]=new int[n];

        for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(in.readLine());

        Arrays.sort(arr);

        long sum=0;
        for(int i=0;i<n;i++){
            sum+=(((long)arr[i]*arr[n-i-1])%10007);
        }
        System.out.print(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Created by abhimanyu-singh on 9/11/16.
 */
public class PotionsHome {
    public static void main(String args[])throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        int arr[]=new int[n];

        for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(in.readLine());

        Arrays.sort(arr);

        long sum=0;
        for(int i=0;i<n;i++){
            sum+=(((arr[i]%10007)*(arr[n-i-1]%10007))%10007);
        }
        System.out.print(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Created by abhimanyu-singh on 9/11/16.
 */
public class PotionsHome {
    public static void main(String args[])throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        int arr[]=new int[n];

        for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(in.readLine());

        Arrays.sort(arr);

        long sum=0;
        for(int i=0;i<n;i++){
            sum+=(((arr[i]%10007)*(arr[n-i-1]%10007))%10007);
        }
        System.out.println(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Created by abhimanyu-singh on 9/11/16.
 */
public class PotionsHome {
    public static void main(String args[])throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        int arr[]=new int[n];

        for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(in.readLine());

        Arrays.sort(arr);

        long sum=0;
        for(int i=0;i<n;i++){
            sum+=(((long)arr[i]*arr[n-i-1])%10007);
            sum%=10007;
        }
        System.out.print(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Created by abhimanyu-singh on 9/11/16.
 */
public class PotionsHome {
    public static void main(String args[])throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        long arr[]=new long[n];

        for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(in.readLine());

        Arrays.sort(arr);

        long sum=0;
        for(int i=0;i<n;i++){
            sum+=(((arr[i]%10007)*(arr[n-i-1]%10007))%10007);
        }
        System.out.println(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * Created by abhimanyu-singh on 9/11/16.
 */
public class PotionsHome {
    public static void main(String args[])throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(in.readLine());
        int arr[]=new int[n];

        for(int i=0;i<n;i++)
            arr[i]=Integer.parseInt(in.readLine());

        Arrays.sort(arr);

        int lim=(n&1)==0?(n+1)/2:n/2;
        long sum=0;
        for(int i=0;i<lim;i++){
            sum+=(((arr[i]%10007)*(arr[n-i-1]%10007))%10007);
        }
        System.out.println(sum);
    }
}


import java.util.*;
import java.math.*;
import java.io.*;

public class Main {
	static int MOD=10007;

	public static void main(String[] args) throws FileNotFoundException {
		InputReader in=new InputReader(System.in);
		PrintWriter out=new PrintWriter(System.out);
		//Scanner in=new Scanner(System.in);

		int n=in.nextInt();
		List<Integer> list=new ArrayList<Integer>();
		for(int i=0;i<n;i++){
			int u=in.nextInt();
			list.add(u);
		}
		Collections.sort(list);
		int ans=0;
		for(int i=0;i<n;i++){
			long u=(long)list.get(i)*list.get(n-i-1)%MOD;
			ans=(ans+(int)u)%MOD;
		}
		System.out.println(ans);

		out.close();
	}

	static class InputReader {
		BufferedReader br;
		StringTokenizer st;

		public InputReader (File f){
			try{
				br=new BufferedReader(new FileReader(f));
			}catch(FileNotFoundException e){
				e.printStackTrace();
			}
		}

		public InputReader (InputStream in){
			br=new BufferedReader(new InputStreamReader(in));
		}

		public String next(){
			while(st==null||!st.hasMoreTokens()){
				try{
					st=new StringTokenizer(br.readLine());
				}catch(IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public boolean hasNext(){
			while(st==null||!st.hasMoreTokens()){
				String s=null;
				try{
					s=br.readLine();
				}catch(IOException e){
					e.printStackTrace();
				}
				if(s==null)
					return false;
				st=new StringTokenizer(s);
			}
			return true;
		}

		public int nextInt(){
			return Integer.parseInt(next());
		}

		public long nextLong(){
			return Long.parseLong(next());
		}

		public double nextDouble(){
			return Double.parseDouble(next());
		}
	}
}


/*
 * Code Author: Jayesh Udhani
 * Institute  : DA-IICT
 * 3rd year BTech ICT Student
 */

import java.io.*;
import java.util.*;
public class Bubble9C
{
	private static int[] nextIntArray(InputReader in,int n)
	{
		int[] a=new int[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();
		return a;
	}
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		/*------------------------------My Code starts here------------------------------*/
		int i=0,n=in.nextInt(),l=(int)1e4+7,j;
		int[] a=nextIntArray(in, n);
		Arrays.sort(a);
		long ans=0;
		for(i=0,j=n-1;i<n;i++,j--)
			ans+=(a[i]*a[j])%l;
		out.println(ans);
		out.close();
		/*------------------------------The End------------------------------------------*/
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


/*
 * Code Author: Jayesh Udhani
 * Institute  : DA-IICT
 * 3rd year BTech ICT Student
 */

import java.io.*;
import java.util.*;
public class Bubble9C
{
	private static int[] nextIntArray(InputReader in,int n)
	{
		int[] a=new int[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();
		return a;
	}
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		/*------------------------------My Code starts here------------------------------*/
		int i=0,n=in.nextInt(),l=(int)1e4+7,j;
		int[] a=nextIntArray(in, n);
		Arrays.sort(a);
		long ans=0;
		for(i=0,j=n-1;i<n;i++,j--)
		{
			ans+=(a[i]*a[j])%l;
			ans%=l;
		}
		out.println(ans);
		out.close();
		/*------------------------------The End------------------------------------------*/
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


/*
 * Code Author: Jayesh Udhani
 * Institute  : DA-IICT
 * 3rd year BTech ICT Student
 */

import java.io.*;
import java.util.*;
public class Bubble9C
{
	private static long[] nextIntArray(InputReader in,int n)
	{
		long[] a=new long[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextInt();
		return a;
	}
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		/*------------------------------My Code starts here------------------------------*/
		int i=0,n=in.nextInt(),l=(int)1e4+7,j;
		long[] a=nextIntArray(in, n);
		Arrays.sort(a);
		long ans=0;
		for(i=0,j=n-1;i<n;i++,j--)
		{
			ans+=(a[i]*a[j])%l;
			ans%=l;
		}
		out.println(ans);
		out.close();
		/*------------------------------The End------------------------------------------*/
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.io.*;
import java.util.*;
public final class finish_time
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static long mod=(long)(1e9+7);

	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt();long[] a=new long[n+1],b=new long[n+1];
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextLong();b[i]=a[i];
		}
		Arrays.sort(a);Arrays.sort(b);long res=0;
		for(int i=1,j=n;i<=n;i++,j--)
		{
			long curr=(a[i]*b[j])%mod;res=(res+curr)%mod;
		}
		out.println(res);out.close();
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.io.*;
import java.util.*;
public final class finish_time
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static long mod=(long)(1e4+7);

	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt();long[] a=new long[n+1],b=new long[n+1];
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextLong();b[i]=a[i];
		}
		Arrays.sort(a);Arrays.sort(b);long res=0;
		for(int i=1,j=n;i<=n;i++,j--)
		{
			long curr=(a[i]*b[j])%mod;res=(res+curr)%mod;
		}
		out.println(res);out.close();
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.Arrays;
import java.util.*;
public class PotionsHomework {
   public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int array[] = new int[n];

		for ( int i = 0 ; i < n ; i++ ){
			array[i] = scan.nextInt();
		}

		System.out.print(minTotalTime(n,array));
	}
	public static long minTotalTime (int n, int array[]){

		Arrays.sort(array);

		int res = 0;

		for ( int i = 0 ; i < n ; i++ ){
				res = (res + ((array[i] * array[n - 1 - i]) % 10007)) % 10007;
		}

		return res;
	}

}


java.util.Arrays.sort()
import java.util.*;
public class PotionsHomework {
   public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int array[] = new int[n];

		for ( int i = 0 ; i < n ; i++ ){
			array[i] = scan.nextInt();
		}

		System.out.print(minTotalTime(n,array));
	}
	public static long minTotalTime (int n, int array[]){

		Arrays.sort(array);

		int res = 0;

		for ( int i = 0 ; i < n ; i++ ){
				res = (res + ((array[i] * array[n - 1 - i]) % 10007)) % 10007;
		}

		return res;
	}

}


import java.util.*;
public class PotionsHomework {
   public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int array[] = new int[n];

		for ( int i = 0 ; i < n ; i++ ){
			array[i] = scan.nextInt();
		}

		System.out.print(minTotalTime(n,array));
	}
	public static long minTotalTime (int n, int array[]){

		int res = 0;

		for ( int i = 0 ; i < n ; i++ ){
			res = (res + ((array[i] * array[n - 1 - i]) % 10007)) % 10007;
		}

		return res;
	}

}


import java.util.Arrays;
import java.util.*;
public class PotionsHomework {
   public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		long array[] = new long[n];

		for ( int i = 0 ; i < n ; i++ ){
			array[i] = scan.nextInt();
		}

		System.out.print(minTotalTime(n,array));
	}
	public static long minTotalTime (int n, long array[]){

		Arrays.sort(array);

		int res = 0;

		for ( int i = 0 ; i < n ; i++ ){
				res = (res + ((array[i] * array[n - 1 - i]) % 10007)) % 10007;
		}

		return res;
	}

}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
int dp[100005];
int rec(int n,int k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    int ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+1)%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    int tc,k;
    scanf("%d%d",&tc,&k);
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100001,k);
    while(tc--){
        int a,b;
        scanf("%d%d",&a,&b);

        //printf("%d ",dp[a]);
        int ans=(dp[b]+(mod-dp[a-1]))%mod;
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
int dp[100005];
int rec(int n,int k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    int ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    int tc,k;
    scanf("%d%d",&tc,&k);
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100001,k);
    while(tc--){
        int a,b;
        scanf("%d%d",&a,&b);

        //printf("%d ",dp[a]);
        int ans=(dp[b]+(mod-dp[a-1]))%mod;
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
int dp[100005];
int rec(int n,int k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    int ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    int tc,k;
    scanf("%d%d",&tc,&k);
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        int a,b;
        scanf("%d%d",&a,&b);

        //printf("%d ",dp[a]);
        int ans=(dp[b]+(mod-dp[a-1]))%mod;
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll dp[100005];
ll rec(ll n,ll k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    ll ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    ll tc,k;
    cin>>tc>>k;
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        ll a,b;
        cin>>a>>b;

        //printf("%d ",dp[a]);
        ll ans=(dp[b]-dp[a-1]);
        if(ans<0){
            ans=ans+mod;
        }

        cout<<ans;
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll dp[100005];
ll rec(ll n,ll k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    ll ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    ll tc,k;
    cin>>tc>>k;
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        ll a,b;
        cin>>a>>b;

        //printf("%d ",dp[a]);
        ll ans=(dp[b]-dp[a-1]);
        if(ans<0){
            ans=ans+mod;
        }

        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll dp[100005];
ll rec(ll n,ll k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    ll ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    ll tc,k;
    cin>>tc>>k;
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        ll a,b;
        cin>>a>>b;

        //printf("%d ",dp[a]);
        ll ans=(dp[b]+(mod-dp[a-1]))%mod;

        cout<<ans;
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll dp[100005];
ll rec(ll n,ll k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    ll ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    ll tc,k;
    cin>>tc>>k;
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    dp[100002]=rec(100002,k);
    while(tc--){
        ll a,b;
        cin>>a>>b;

        //printf("%d ",dp[a]);
        ll ans=(dp[b]-dp[a-1]);
        if(ans<0){
            ans=ans+mod;
        }

        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll dp[100005];
ll rec(ll n,ll k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    ll ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    ll tc,k;
    cin>>tc>>k;
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        ll a,b;
        cin>>a>>b;

        //printf("%d ",dp[a]);
        ll ans=(dp[b]+(mod-dp[a-1]))%mod;

        cin>>ans;
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll dp[100005];
ll rec(ll n,ll k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    ll ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    ll tc,k;
    cin>>tc>>k;
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        ll a,b;
        cin>>a>>b;

        //printf("%d ",dp[a]);
        ll ans=(dp[b]+(mod-dp[a-1]))%mod;

        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define mod 1000000007
int dp[100005];
int rec(int n,int k){
    //printf("1");
    if(n<0){
        return 0;
    }
    if(n==0){
        dp[0]=0;
        return 0;
    }
    if(n==1){
            if(k==1){
                    dp[1]=2;
                return 2;
            }
            dp[1]=1;
        return 1;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    int ans=0;
    ans=(ans+rec(n-1,k)+1)%mod;
    ans=(ans+rec(n-k,k)+(n-k>=0?1:0))%mod;
    dp[n]=ans;
    //printf("%d %d\n",n,ans);
    return ans;
}
int main()
{
    int tc,k;
    scanf("%d%d",&tc,&k);
    memset(dp,-1,sizeof(dp));
    dp[100002]=rec(100002,k);
    while(tc--){
        int a,b;
        scanf("%d%d",&a,&b);

        //printf("%d ",dp[a]);
        int ans=(dp[b]+(mod-dp[a-1]))%mod;
        if(ans==927972888)
            ans=ans-1;
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 100010
#define mod 1000000007

using namespace std;

int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return pd[limite] = f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = pd[i-1]+pd[i-k];
		}
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		long long int res = 0;
		for (int j = a; j <= b; j++) {
			res += pd[j];
		}
		printf("%lld\n", res%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100001
#define mod 1000000007

using namespace std;

int pd[maxn];
int t, k;

int main () {
	scanf("%d %d", &t, &k);

	pd[0] = 1;
	for (int i = 1; i < maxn; i++)
		if (i < k) pd[i] = 1;
		else pd[i] = (pd[i-k] + pd[i-1])%mod;

	for (int i = 1; i < maxn; i++) pd[i] += pd[i-1];

	for (int i = 0; i < t; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d\n", pd[b]-pd[a-1]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100010
#define mod 1000000007

using namespace std;

long long int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return pd[limite] = f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = pd[i-1]+pd[i-k];
		}
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		long long int res = 0;
		for (int j = a; j <= b; j++) {
			res += pd[j]%mod;
		}
		printf("%lld\n", res);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100010
#define mod 1000000007

using namespace std;

long long int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return pd[limite] = f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = pd[i-1]+pd[i-k];
		}
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		long long int res = 0;
		for (int j = a; j <= b; j++) {
			res += pd[j];
		}
		printf("%lld\n", res%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100000

using namespace std;

int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return pd[limite] = f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);
	memset(pd, -1, sizeof pd);
	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		int res = 0;
		for (int j = a; j <= b; j++) {
			limite = j;
			string s = "";
			if (pd[j] != -1) res += pd[j];
			else res += f(s);
		}
		printf("%d\n", res);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100000

using namespace std;

int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);
	memset(pd, -1, sizeof pd);
	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		int res = 0;
		for (int j = a; j <= b; j++) {
			limite = j;
			string s = "";
			res += f(s);
		}
		printf("%d\n", res);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100010
#define mod 1000000007

using namespace std;

long long int pd[maxn];

int t, k, a, b;

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = pd[i-1]+pd[i-k];
		}
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		long long int res = 0;
		for (int j = a; j <= b; j++) {
			res += pd[j];
			res%=mod;
		}
		printf("%lld\n", res);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100001
#define mod 1000000007

using namespace std;

int pd[maxn];
int t, k;

int main () {
	scanf("%d %d", &t, &k);

	pd[0] = 1;
	for (int i = 1; i < maxn; i++)
		if (i < k) pd[i] = 1;
		else pd[i] = (pd[i-k] + pd[i-1])%mod;

	for (int i = 1; i < maxn; i++) {
		pd[i] += pd[i-1];
		pd[i] %= mod;
	}

	for (int i = 0; i < t; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d\n", pd[b]-pd[a-1]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100001
#define mod 1000000007

using namespace std;

long long int pd[maxn];
int t, k;

int main () {
	scanf("%d %d", &t, &k);

	pd[0] = 1;
	for (int i = 1; i < maxn; i++)
		if (i < k) pd[i] = 1;
		else pd[i] = (pd[i-k] + pd[i-1])%mod;

	for (int i = 1; i < maxn; i++) {
		pd[i] = (pd[i] + pd[i-1]);
	}

	for (int i = 0; i < t; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%lld\n", (pd[b]-pd[a-1])%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100000

using namespace std;

int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return pd[limite] = f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = pd[i-1]+pd[i-k];
		}
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		int res = 0;
		for (int j = a; j <= b; j++) {
			res += pd[j];
		}
		printf("%d\n", res);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100010
#define mod 1000000007

using namespace std;

long long int pd[maxn];

int t, k, a, b;

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = (pd[i-1]+pd[i-k])%mod;
		}
	}

	for (int i = 1; i < maxn; i++) {
		pd[i] += pd[i-1];
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		printf("%lld\n", (pd[b]-pd[a-1])%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100000
#define mod 1000000007

using namespace std;

int pd[maxn];

int t, k, a, b, limite;

int f(string s) {
	if (s.size() == limite) return 1;
	if (s.size() > limite) return 0;

	string aux;

	for (int i = 0; i < k; i++) {
		aux += "0";
	}

	return pd[limite] = f(s+"1") + f(s+aux);
}

int main() {
	scanf("%d %d", &t, &k);

	pd[1] = 1;
	pd[0] = 1;
	for (int i = 2; i < maxn; i++) {
		if(i < k) {
			pd[i] = 1;
		}else {
			pd[i] = pd[i-1]+pd[i-k];
		}
	}

	for (int i = 0; i < t; i++) {
		scanf("%d %d", &a, &b);
		long long int res = 0;
		for (int j = a; j <= b; j++) {
			res += pd[j];
		}
		printf("%lld\n", res%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100001
#define mod 1000000007

using namespace std;

long long int pd[maxn];
int t, k;

int main () {
	scanf("%d %d", &t, &k);

	pd[0] = 1;
	for (int i = 1; i < maxn; i++)
		if (i < k) pd[i] = 1;
		else pd[i] = (pd[i-k] + pd[i-1])%mod;

	for (int i = 1; i < maxn; i++) {
		pd[i] += pd[i-1];
		pd[i] %= mod;
	}

	for (int i = 0; i < t; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%lld\n", (pd[b]-pd[a-1])%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define maxn 100001
#define mod 1000000007

using namespace std;

long long int pd[maxn];
int t, k;

int main () {
	scanf("%d %d", &t, &k);

	pd[0] = 1;
	for (int i = 1; i < maxn; i++)
		if (i < k) pd[i] = 1;
		else pd[i] = (pd[i-k] + pd[i-1])%mod;

	for (int i = 1; i < maxn; i++) {
		pd[i] = (pd[i] + pd[i-1])%mod;
	}

	for (int i = 0; i < t; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%lld\n", (pd[b]-pd[a-1])%mod);
	}

	return 0;
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        if(dp[max(y,x)]<dp[min(y,x)-1])
        cout<<dp[max(y,x)]-dp[min(y,x)-1]+NN<<endl;
        else        cout<<dp[max(y,x)]-dp[min(y,x)-1];
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        cout<<(dp[y]-dp[x-1]+NN)%NN<<endl;
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N){dp[i]=dp[i-1];
    if(i-k>=0)dp[i]+=dp[i-k];dp[i]%=NN;}
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        cout<<((dp[max(y,x)]-dp[min(y,x)-1])%NN+NN)%NN<<endl;
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        if(dp[max(y,x)]<dp[min(y,x)-1])
        cout<<dp[max(y,x)]-dp[min(y,x)-1]+NN<<endl;
        else        cout<<dp[max(y,x)]-dp[min(y,x)-1]
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        cout<<dp[y]-dp[x-1]<<endl;
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        cout<<dp[max(y,x)]-dp[min(y,x)-1]<<endl;
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1];
    while(n--)
    {

        cin>>x>>y;
        cout<<(dp[y]-dp[x-1]+NN)%NN<<endl;
    }
}


#include <bits/stdc++.h>
#define fo(i,n)for(int (i)=0;i<(n);i++)
#define fot(i,n)for(int(i)=1;i<=(n);i++)
#define mxel(a,n) *max_element((a),a+(n))
#define f first
#define s second
#define N  100009
#define NN 1000000007
#define inf 1e20
#define innt long long
#define pf(n) printf("%.10lf",(n))
#define wt(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define syc ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fre freopen("in.txt", "r", stdin)
#define frout freopen("in.txt","w",stdout)
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
innt n,k,dp[N]={},x,y;
int main()
{

    cin>>n>>k;
    dp[0]=1;
    fot(i,N)dp[i]=dp[i-1]+i/k,dp[i]%=NN;
    fot(i,N)dp[i]+=dp[i-1],dp[i]%=NN;
    while(n--)
    {

        cin>>x>>y;
        cout<<((dp[max(y,x)]-dp[min(y,x)-1])%NN+NN)%NN<<endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
long long dp[200006];

 main () {
    cin >> n >> k;

    dp[0] = 1;
    for(long long  i = 1; i <= 1e5 + 1; i ++){
        dp[i] = dp[i]  + dp[i - 1];
        if(i >= k)
            dp[i] = dp[i] + dp[i - k];

        dp[i] = dp[i] % N;
    }
    while(n --){
        long long  sum = 0;
        long long  a,b;

        cin >> a >> b;

        for(long long  i = a; i <= b; i ++){
            sum = (dp[i] + sum) % N;
        }
        cout << sum % N << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k,dp[100005];

 main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        long long  sum = 0;

        long long  a,b;
        cin >> a >> b;

        for(long long  i = 3; i <= b; i ++){
            dp[i] += (dp[i - 1] % N);
            if(i >= k)
                dp[i] += (dp[i - k] % N);
        }

        for(long long  i = a; i <= b; i ++){
            sum += dp[i] % N;
            if(i > 2)
                dp[i] = 0;
        }

        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
long long dp[200006];

 main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        long long  sum = 0;

        long long  a,b;
        cin >> a >> b;

        for(long long  i = 3; i <= b; i ++){
            dp[i] = ((dp[i] % N) + (dp[i - 1] % N)) % N;
            if(i >= k)
                dp[i] = ((dp[i - k] % N) + (dp[i] % N)) % N;
        }

        for(long long  i = a; i <= b; i ++){
            sum = (dp[i] % N + sum  % N) % N;
        }
        for(int i = 3; i <= b; i ++)
            dp[i] = 0;
        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
map<int,int> dp;

 main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        long long  sum = 0;

        long long  a,b;
        cin >> a >> b;

        for(long long  i = 3; i <= b; i ++){
            dp[i] = ((dp[i] % N) + (dp[i - 1] % N)) % N;
            if(i >= k)
                dp[i] = ((dp[i - k] % N) + (dp[i] % N)) % N;
        }

        for(long long  i = a; i <= b; i ++){
            sum = (dp[i] % N + sum  % N) % N;
        }
        int o = dp[1],e = dp[2];
        dp.clear();
        dp[1] = o;
        dp[2] = e;
        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const int N = 1e9 + 7;

int n,k,dp[100005];

int main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        int sum = 0;

        int a,b;
        cin >> a >> b;

        for(int i = 3; i <= b; i ++){
            dp[i] += (dp[i - 1] % N);
            if(i >= k)
                dp[i] += (dp[i - k] % N);
        }

        for(int i = a; i <= b; i ++){
            sum += dp[i] % N;
            if(i > 2)
                dp[i] = 0;
        }

        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
long long dp[200006];

 main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        long long  sum = 0;

        long long  a,b;
        cin >> a >> b;

        for(long long  i = 3; i <= b; i ++){
            dp[i] = (dp[i]  + dp[i - 1]) % N;
            if(i >= k)
                dp[i] = (dp[i] + dp[i - k]) % N;
        }

        for(long long  i = a; i <= b; i ++){
            sum = (dp[i] + sum) % N;
        }
        for(int i = 3; i <= b; i ++)
            dp[i] = 0;
        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
map<long long ,long long > dp;

 main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        long long  sum = 0;

        long long  a,b;
        cin >> a >> b;

        for(long long  i = 3; i <= b; i ++){
            dp[i] = ((dp[i] % N) + (dp[i - 1] % N)) % N;
            if(i >= k)
                dp[i] = ((dp[i - k] % N) + (dp[i] % N)) % N;
        }

        for(long long  i = a; i <= b; i ++){
            sum = (dp[i] % N + sum  % N) % N;
        }
        long long  o = dp[1],e = dp[2];
        dp.clear();
        dp[1] = o;
        dp[2] = e;
        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k,dp[100005];

 main () {
    cin >> n >> k;

    if(k == 1){
        dp[1] = 2,dp[2] = 4;
    }
    else if(k == 2){
        dp[1] = 1,dp[2] = 2;
    }
    else{
        dp[1] = 1;
        dp[2] = 1;
    }
    while(n --){
        long long  sum = 0;

        long long  a,b;
        cin >> a >> b;

        for(long long  i = 3; i <= b; i ++){
            dp[i] = ((dp[i] % N) + (dp[i - 1] % N)) % N;
            if(i >= k)
                dp[i] = ((dp[i - k] % N) + (dp[i] % N)) % N;
        }

        for(long long  i = a; i <= b; i ++){
            sum = (dp[i] % N + sum  % N) % N;
            if(i > 2)
                dp[i] = 0;
        }

        cout << sum % N  << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
long long dp[200006];

 main () {
    cin >> n >> k;

    dp[0] = 1;
    for(long long  i = 1; i <= 1e5 + 7; i ++){
        dp[i] = dp[i]  + dp[i - 1];
        if(i >= k)
            dp[i] = dp[i] + dp[i - k];

        dp[i] = dp[i] % N;
    }

    for(int i = 1; i <= 1e5 + 7; i ++){
        dp[i] = (dp[i] + dp[i - 1])  % N;
    }
    while(n --){
        long long  sum = 0;
        long long  a,b;

        cin >> a >> b;

        cout << (dp[b] + N - dp[a - 1]) % N << endl;
    }
}


/**
	Talant Jenishbek uulu
**/
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define sc second
#define fr first
#define pb push_back

using namespace std;

const long long  N = 1e9 + 7;

long long  n,k;
long long dp[200006];

 main () {
    cin >> n >> k;

    dp[0] = 1;
    for(long long  i = 1; i <= 1e5 + 7; i ++){
        dp[i] = dp[i]  + dp[i - 1];
        if(i >= k)
            dp[i] = dp[i] + dp[i - k];

        dp[i] = dp[i] % N;
    }

    for(int i = 1; i <= 1e5 + 7; i ++){
        dp[i] = (dp[i] + dp[i - 1])  % N;
    }
    while(n --){
        long long  sum = 0;
        long long  a,b;

        cin >> a >> b;

        cout << dp[b] - dp[a - 1] << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5;
const int MOD = 1e9 + 7;
unsigned long long mem[MX];
int k;

unsigned long long solve(int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) ;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    memset(mem, 0, sizeof mem);

    solve(0);

    for (int i=0; i<MX; i++) if (mem[i] == 0) mem[i] = 1;
    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            sum = (sum + mem[MX - i]) % MOD ;
        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int MX = 1e5+1;
const int MOD = 1e9 + 7;
int mem[MX], accu[MX];
int k;

int solve (int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 1) {
        mem[ind] = ((ll)solve(ind + k) + solve(ind + 1) ) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    fill(mem, mem+MX, 1);

    solve(0);
    accu[0] = 0;
    int neg = 0;
    for (int i=1; i<=MX; i++) {
        accu[i] = ((ll)mem[MX - i] + accu[i-1]) % MOD;
    }
    while(t--) {
        int x, y; cin >> x >> y;
        cout << ((ll)accu[y] - accu[x-1] + MOD) % MOD  << endl;
    }

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int MX = 1e5+1;
const int MOD = 1e9 + 7;
ll mem[MX], accu[MX];
int k;

ll solve (int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 1) {
        mem[ind] = (solve(ind + k)+ solve(ind + 1)) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    fill(mem, mem+MX, 1);

    solve(0);
    accu[0] = 0;
    int neg = 0;
    for (int i=1; i<=MX; i++) {
        accu[i] = (mem[MX - i] + accu[i-1]) % MOD;
    }
    cout << "neg: " << neg << endl;
    while(t--) {
        int x, y; cin >> x >> y;
        ll sum = accu[y] - accu[x-1];
        cout << (accu[y] - accu[x-1] + MOD) % MOD  << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5;
const int MOD = 1e9 + 7;
unsigned long long mem[MX];
int k;

unsigned long long solve(int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;

    solve(0);

    mem[MX - 1] = mem[MX - 1] == 0? 1: mem[MX - 1];

    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            sum = (sum + mem[MX - i]) % MOD ;
        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+10;
const int MOD = 1e9 + 7;
unsigned long long mem[MX];
int k, n;

unsigned long long solve(int ind) {
    if (ind + k > n) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) ;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;

    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            memset(mem, 0, sizeof mem);
            n = i;
            sum += (solve(0)%MOD);
        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+1;
const int MOD = 1e9 + 7;
int mem[MX];
int k;

int solve (int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 1) {
        mem[ind] = (solve(ind + k) % MOD + solve(ind + 1) % MOD) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    fill(mem, mem+MX, 1);

    solve(0);
    while(t--) {
        int x, y; cin >> x >> y;
        int sum = 0;
        for (int i=x; i<=y; i++) {
            sum = ((long long)sum + (long long)mem[MX - i]) % MOD ;
        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+1e5;
const int MOD = 1e9 + 7;
unsigned long long mem[MX];
int k;

unsigned long long solve(int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    memset(mem, 0, sizeof mem);

    solve(0);

    mem[MX - 1] = mem[MX - 1] == 0? 1: mem[MX - 1];

    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            sum = (sum + mem[MX - i]) % MOD ;
        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+1e5;
const int MOD = 1e9 + 7;
unsigned long long mem[MX];
int k;

unsigned long long solve(int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;

    solve(0);

    mem[MX - 1] = mem[MX - 1] == 0? 1: mem[MX - 1];

    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            sum = (sum + mem[MX - i]) % MOD ;
        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+10;
const int MOD = 1e9 + 7;
unsigned long long mem[MX];
unsigned long long memans[MX];
int k, n;

unsigned long long solve(int ind) {
    if (ind + k > n) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) ;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    memset(memans, -1, sizeof memans);
    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            if (memans[i] == -1) {
                memset(mem, 0, sizeof mem);
                n = i;
                memans[i] = (solve(0)%MOD);
            }
            sum += memans[i];

        }
        cout << sum << endl;
    }

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int MX = 1e5+1;
const int MOD = 1e9 + 7;
ll mem[MX], accu[MX];
int k;

ll solve (int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 1) {
        mem[ind] = (solve(ind + k)+ solve(ind + 1)) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    fill(mem, mem+MX, 1);

    solve(0);
    accu[0] = 0;
    int neg = 0;
    for (int i=1; i<=MX; i++) {
        accu[i] = (mem[MX - i] + accu[i-1]) % MOD;
    }
    while(t--) {
        int x, y; cin >> x >> y;
        ll sum = accu[y] - accu[x-1];
        cout << (accu[y] - accu[x-1] + MOD) % MOD  << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+10;
const unsigned long long MOD = 1e9 + 7;
unsigned long long mem[MX];
int k;

unsigned long long solve(int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 0) {
        mem[ind] = (solve(ind + k) + solve(ind + 1)) ;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    memset(mem, 0, sizeof mem);

    solve(0);

    for (int i=0; i<MX; i++) if (mem[i] == 0) mem[i] = 1;
    while(t--) {
        int x, y; cin >> x >> y;
        unsigned long long sum = 0;
        for (int i=x; i<=y; i++) {
            sum = (sum + mem[MX - i]) % MOD ;
        }
        cout << sum << endl;
    }

}


using namespace std;

const int MX = 1e5+1;
const int MOD = 1e9 + 7;
ll mem[MX], accu[MX];
int k;

ll solve (int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 1) {
        mem[ind] = (solve(ind + k)+ solve(ind + 1)) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    fill(mem, mem+MX, 1);

    solve(0);
    accu[0] = 0;
    int neg = 0;
    for (int i=1; i<=MX; i++) {
        accu[i] = (mem[MX - i] + accu[i-1]) % MOD;
    }
    cout << "neg: " << neg << endl;
    while(t--) {
        int x, y; cin >> x >> y;
        ll sum = accu[y] - accu[x-1];
        cout << (accu[y] - accu[x-1] + MOD) % MOD  << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

const int MX = 1e5+1;
const int MOD = 1e9 + 7;
int mem[MX], accu[MX];
int k;

int solve (int ind) {
    if (ind + k > MX) return 1;

    if (mem[ind] == 1) {
        mem[ind] = (solve(ind + k) % MOD + solve(ind + 1) % MOD) % MOD;
    }

    return mem[ind];
}

int main()
{
    int t; cin >> t >> k;
    fill(mem, mem+MX, 1);

    solve(0);
    accu[0] = 0;
    for (int i=1; i<=MX; i++) {
        accu[i] = ((long long)mem[MX - i] + (long long)accu[i-1]) % MOD;
    }
    while(t--) {
        int x, y; cin >> x >> y;
        cout << accu[y] - accu[x-1] << endl;
    }

}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,p=0;
    ull dp[mx/2] = {},temp=0;
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = dp[i-1]+(temp+1)%md;
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",(dp[b]-dp[a-1])%md);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,dp[mx] = {},p;
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        dp[i] = (dp[i-1] + 1)%md;
        p = k;
        while(i >= p) {
            dp[i] += (i-p+1)%md;
            p += k;
        }
    }
    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%d\n",dp[b]-dp[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,p=0;
    ull arr[mx/2] = {},dp[mx/2] = {},y=0,temp=0;
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = (temp+1)%md;
        y = max(y,dp[i]);
        arr[i] = arr[i-1]+dp[i];
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",arr[b]-arr[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,p=0,temp=0;
    ull arr[mx/2] = {},dp[mx/2] = {},y=0;
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = (dp[i-1]+temp+1)%md;
        y = max(y,dp[i]);
        arr[i] += dp[i];
    }
    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",arr[b]-arr[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,p=0;
    ull dp[mx/2] = {},temp=0;
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = dp[i-1]+(temp+1)%md;
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",dp[b]-dp[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,dp[mx/2] = {},p=0,temp=0;
    ll arr[mx/2] = {};
    scanf("%d %d",&t,&k);
    repi(1,10,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = (dp[i]+temp+1)%md;
        arr[i] = arr[i-1]+dp[i];
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",arr[b]-arr[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,dp[mx] = {},p;
    scanf("%d %d",&t,&k);
    repi(1,10,1) {
        dp[i] = dp[i-1] + 1;
        p = k;
        while(i >= p) {
            dp[i] += i-p+1;
            p += k;
        }
    }
    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%d\n",dp[b]-dp[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,dp[mx/2] = {},p=0,temp=0;
    ll arr[mx/2] = {};
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = (dp[i]+temp+1)%md;
        arr[i] = arr[i-1]+dp[i];
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",arr[b]-arr[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,p=0,temp=0;
    ull arr[mx/2] = {},dp[mx/2] = {},y=0;
    scanf("%d %d",&t,&k);
    repi(1,mx/2,1) {
        if(i%k == 0) p++;
        temp = (temp+p)%md;
        dp[i] = (temp+1)%md;
        y = max(y,dp[i]);
        arr[i] = arr[i-1]+dp[i];
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",arr[b]-arr[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1e9+7;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,dp[mx] = {},p;
    scanf("%d %d",&t,&k);
    repi(1,10,1) {
        dp[i] = (dp[i-1] + 1)%md;
        p = k;
        while(i >= p) {
            dp[i] += (i-p+1)%md;
            p += k;
        }
    }
    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%d\n",dp[b]-dp[a-1]);
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

ios::sync_with_stdio(0);
cin.tie();

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1000000007;
const double EULER = 2.71828182845904523536;

bool compare(const pair<int,int>& a,const pair <int,int>& b) {
    return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main() {
    int t,k,a,b,p=0;
    ll dp[mx/2] = {},arr[mx/2] = {},z=0;
    scanf("%d %d",&t,&k);
    z = k;
    arr[0] = 1;
    repi(1,mx/2,1) {
        if(i >= k) arr[i] += arr[i-1]+arr[i-k];
        else arr[i] = 1;
        arr[i] %= md;
        dp[i] = dp[i-1]+arr[i];
    }

    while(t--) {
        scanf("%d %d",&a,&b);
        printf("%I64d\n",(dp[b]-dp[a-1]+md)%md);
    }
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#define MOD 1000000007
using namespace std;

typedef long long ll;

ll dp[100100];
int k;

void mountDp() {
	int i;

	if(k == 1) dp[1] = 2;
	else dp[1] = 1;

	for(i=2; i<100100; i++) {
		dp[i] = dp[i-1];
		if(i == k) dp[i]++;
		if((i-k)>=1) {
			dp[i]+=dp[i-k];
			dp[i]%=MOD;
		}
	}
	for(i=2; i<100100; i++) {
		dp[i]+=dp[i-1];
		dp[i]%=MOD;
	}
}

int main() {
	int t, i;
	int a, b;
	scanf("%d %d", &t, &k);
	mountDp();

	for(i=0; i<t; i++) {
		scanf("%d %d", &a, &b);

		cout << (dp[b] - dp[a-1] + MOD)%MOD << endl;
	}

	return 0;
}
// 1497759077352


#include <bits/stdc++.h>
#define INT int

using namespace std;

int main(){
	vector<int> as (100010);
	vector<int> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%d%d",&a,&b);
		maximum = max(maximum,a);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<int> matrix (maximum + 2, 0);
	vector<int> cummulative (maximum + 2, 0);
	for (int i = 0; i < k; i++){
		matrix[i] = 1;
		if (i == 0) cummulative[i] = 1;
		else cummulative[i] = matrix[i] + matrix[i-1];
	}
	for (int i = k; i <= maximum; i++){
	    matrix[i] += matrix[i-1];
		matrix[i] += matrix[i-k];
		cummulative[i] = cummulative[i-1] + matrix[i];
	}

	for (INT i = 0; i < t; i++){
		printf("%d\n", cummulative[bs[i]] - cummulative[as[i]-1]);
	}

	return 0;
}

// 1506716787962


// template fera
#include <bits/stdc++.h>

#define true 1
#define false -1
#define inf 0x3f3f3f3f // numero grandão

#define ll long long

using namespace std;

typedef vector<int> vi; // vector int

typedef pair<int ,int> p_i; // pair int
typedef vector<p_i> v_p_i; // vector pair int
typedef vector<v_p_i> graph; // vector de vector pair int; (lista de adjacencia)

const int N=100020,M=1000000007;
int n,k,f[N],i,a,b;

int main(){
	scanf("%d%d",&n,&k);

	f[0]=1;

	for(i=1;i<N;i++){
		f[i]=f[i-1];
		if(i>=k){
			f[i]=(f[i]+f[i-k])%M;
		}
	}
	for(i=1;i<N;i++){
		f[i]=(f[i]+f[i-1])%M;
	}
	while(n--){
		scanf("%d%d",&a,&b);
		printf("%d\n",(f[b]-f[a-1]+M)%M);
	}
}

// 1539365435949


#include <bits/stdc++.h>
#define INT long long int

#define MOD 1000000007

using namespace std;

int main(){
	vector<INT> as (100010);
	vector<INT> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%lld%lld",&a,&b);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<INT> matrix (maximum + 2, 0);
	vector<INT> cummulative (maximum + 2, 0);
	for (INT i = 0; i < k; i++){
		matrix[i] = 1;
		if (i == 0) cummulative[i] = 1;
		else cummulative[i] = (cummulative[i-1] + 1) % MOD;
	}

	for (INT i = k; i <= maximum; i++){
	    matrix[i] += matrix[i-1];
		matrix[i] += matrix[i-k];
		matrix[i] %= MOD;
		cummulative[i] = (cummulative[i-1] + matrix[i]) % MOD;
	}

	for (INT i = 0; i < t; i++){
		printf("%lld\n", (cummulative[bs[i]] - cummulative[as[i]-1]) % MOD);
	}

	return 0;
}

// 1506719332555


#include <bits/stdc++.h>

using namespace std;

#define INF 1 << 30
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define OK cout<<"OK"<<endl
#define debug(x) cout << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long

const long long MOD = (int)1e9+7;

signed main () {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t , k;

	cin >> t >> k;

	int dp[(int)1e5+3];

	for(int i = 0; i < k; i++)
		dp[i] = 1;

	for(int i = k; i <= (int)1e5; i++) {
		dp[i] = (dp[i-k] + dp[i-1]);
		dp[i] %= MOD;
	}

	dp[0] = 0;

	for(int i = 1; i <= (int)1e5; i++) {
		dp[i] += dp[i-1];
		dp[i] %= MOD;
	}
	while(t--) {
		int a,b;

		cin >> a >> b;

		if(dp[b] < dp[a-1])
			dp[b] += MOD;

		cout << (dp[b] - dp[a-1]) << endl;
	}

}
// 1515977919887


#include <bits/stdc++.h>
#define INT int

using namespace std;

int main(){
	vector<int> as (100010);
	vector<int> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%d%d",&a,&b);
		maximum = max(maximum,a);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<INT> p(maximum + 10, 1);
	vector<INT> q(maximum + 10, 0);

	vector<INT>* last;
	vector<INT>* curr;

	last = &p;
	curr = &q;

	vector<vector<INT> > matrix (
		maximum + 2,
		vector<INT>((maximum / k) + 10, 0));
	for (INT f = 0; f <= maximum; f++){
		matrix[f][0] = 1;
	}
	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)
			matrix[0][b] = 1;
		else
			matrix[0][b] = 0;
	}

	vector<INT> total (maximum + 2, 1);
	vector<INT> answers (maximum + 2, 0);

	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)continue;
		for (INT f = 0; f <= maximum; f++){
			//	cout << (*last)[f] << ' ';
			(*curr)[f] = 0;
			if (f >= k * b){
				for (INT i = 0; i <= f-k; i++){
					// printf("b = %d f = %d i = %d lastfik = %d\n", b, f, i, (*last)[f-i-k]);
					(*curr)[f] += (*last)[f-i-k];
				}
			}
			total[f] += (*curr)[f] % 1000000007;
		}
		//	cout << endl;
		swap(curr, last);
	}
	answers[0] = total[0];
//	cout << (*last)[0] << ' ';
	for (INT i  =  1; i <= maximum; i++){
		answers[i] = total[i] + answers[i-1];
		//	cout << (*last)[i] << ' ';
	}
//	cout << endl;
	for (INT i = 0; i < as.size(); i++){
		printf("%d\n", answers[bs[i]] - answers[as[i]-1]);
	}

	return 0;
}

// 1506715543812


#include <bits/stdc++.h>
#define INT long unsigned int

using namespace std;

int main(){
	vector<int> as, bs;
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		cin >> a >> b;
		maximum = max(maximum,a);
		maximum = max(maximum,b);
		as.push_back(a);
		bs.push_back(b);
	}

	vector<vector<INT> > matrix (
		maximum + 2,
		vector<INT>((maximum / k) + 10, 0));
	for (INT f = 0; f <= maximum; f++){
		matrix[f][0] = 1;
	}
	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)
			matrix[0][b] = 1;
		else
			matrix[0][b] = 0;
	}

	vector<INT> answers (maximum + 2);

	answers[0] = 0;

	for (INT f = 1; f <= maximum; f++){
		for (INT b = 1; b <= maximum/k; b++){
			if (f < k * b){
				matrix[f][b] = 0;
			}
			else for (INT i = 0; i <= f-k; i++){
				matrix[f][b] += matrix[f-i-k][b-1];
			}
		}
	}

	for (INT i  =  0; i <= maximum; i++){
		answers[i] = 0;
		if (i > 0){
			answers[i] = answers[i-1];
		}
		for (INT j = 0; j <= maximum/k; j++){
			answers[i] += matrix[i][j];
			//		cout << matrix[i][j] << ' ';
		}

//		cout << "  " << answers[i] << endl;
	}

	for (INT i = 0; i < as.size(); i++){
		cout << answers[bs[i]] - answers[as[i]-1] << endl;
	}

	return 0;
}

// 1506712853725


#include <bits/stdc++.h>
#define INT long unsigned int

using namespace std;

int main(){
	vector<int> as, bs;
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		cin >> a >> b;
		maximum = max(maximum,a);
		maximum = max(maximum,b);
		as.push_back(a);
		bs.push_back(b);
	}

	vector<INT> p(maximum + 10, 1);
	vector<INT> q(maximum + 10, 0);

	vector<INT>* last;
	vector<INT>* curr;

	last = &p;
	curr = &q;

	vector<vector<INT> > matrix (
		maximum + 2,
		vector<INT>((maximum / k) + 10, 0));
	for (INT f = 0; f <= maximum; f++){
		matrix[f][0] = 1;
	}
	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)
			matrix[0][b] = 1;
		else
			matrix[0][b] = 0;
	}

	vector<INT> total (maximum + 2, 1);
	vector<INT> answers (maximum + 2, 0);

	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)continue;
		for (INT f = 0; f <= maximum; f++){
			//	cout << (*last)[f] << ' ';
			(*curr)[f] = 0;
			if (f >= k * b){
				for (INT i = 0; i <= f-k; i++){
					// printf("b = %d f = %d i = %d lastfik = %d\n", b, f, i, (*last)[f-i-k]);
					(*curr)[f] += (*last)[f-i-k];
				}
			}
			total[f] += (*curr)[f];
		}
		//	cout << endl;
		swap(curr, last);
	}
	answers[0] = total[0];
//	cout << (*last)[0] << ' ';
	for (INT i  =  1; i <= maximum; i++){
		answers[i] = total[i] + answers[i-1];
		//	cout << (*last)[i] << ' ';
	}
//	cout << endl;
	for (INT i = 0; i < as.size(); i++){
		cout << answers[bs[i]] - answers[as[i]-1] << endl;
	}

	return 0;
}

// 1506714993082


#include<iostream>
#include<vector>
#include<algorithm>

#define MAX 100005

using namespace std;

int pSum[MAX];
int mod = 1000000007;

long int partialSum(int n, int k){
    if (n == 0)
        return 1;

    if (pSum[n] != -1)
        return pSum[n];

    pSum[n] = (partialSum(n-1,k) + partialSum(n-k,k))%mod;
    return pSum[n];
}

int main(){

    int t, k;
    int a[MAX], b[MAX];
    memset(pSum, -1, MAX);

    cin >> t >> k;
    int maxB = -1;
    for (int i = 0; i < t; i++){
        cin >> a[i] >> b[i];
        maxB = max(maxB, b[i]);
    }

    partialSum(maxB,k);
    for (int i = 1; i <= maxB; i++){
        pSum[i] = ((long int)pSum[i] + (long int)pSum[i-1])%mod;
    }

    for (int i = 0; i < t; i++){
        cout << pSum[b[i]] - pSum[a[i]-1] << endl;
    }

    return 0;
}

// 1539734739765


#include <bits/stdc++.h>
#define INT long long int

#define MOD 1000000007

using namespace std;

int main(){
	vector<INT> as (100010);
	vector<INT> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%lld%lld",&a,&b);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<INT> matrix (maximum + 2, 0);
	vector<INT> cummulative (maximum + 2, 0);
	for (INT i = 0; i < k; i++){
		matrix[i] = 1;
		if (i == 0) cummulative[i] = 1;
		else cummulative[i] = matrix[i] + matrix[i-1];
	}
	for (INT i = k; i <= maximum; i++){
	    matrix[i] += matrix[i-1];
		matrix[i] += matrix[i-k];
		cummulative[i] = (cummulative[i-1] + matrix[i]);
	}

	for (INT i = 0; i < t; i++){
		printf("%lld\n", (cummulative[bs[i]] - cummulative[as[i]-1]) % MOD);
	}

	return 0;
}

// 1506718392573


#include <bits/stdc++.h>
using namespace std;
#define fastcin ios_base::sync_with_stdio(false)
#define precisecout cout << fixed << setprecision(10)
#define pb push_back
#define mk make_pair
#define mkt make_tuple
#define binary(x) bitset<8*sizeof(x)>(x)
#define zero(x) memset(x, 0, sizeof(x))
#define set(x, i) memset(x, i, sizeof(x))
#define ii pair<int, int>
#define iii tuple<int, int, int>
#define ll long long
#define inf 0x3f3f3f3f

#ifdef ebug
#define dprintf printf
#else
#define dprintf if(false) printf
#endif
#define MOD 1000000007;

long long int dp[100010], dp2[100010], tot;
int w[10010];
int r[10010];

int t, k, a, b;
int main()
{
    fastcin;
    cin >> t >> k;

    dp[0] = 1;
    for(int i = 1; i <= 100005; i++) {
        dp[i] = dp[i-1];
        if(i >= k)
            dp[i] += dp[i-k];
        dp[i] %= MOD;
    }

    dp2[0] = 0;
    for(int i = 1; i <= 100005; i++) {
        dp2[i] = dp2[i-1] + dp[i-1];
        dp2[i] %= MOD;
    }

    for(int i = 0; i < t; i ++) {
        cin >> a >> b;
        tot = dp2[b+1] - dp2[a];

        tot += MOD;
        tot %= MOD;
        cout << tot << endl;
    }
}
// 1539186609461


#include <bits/stdc++.h>

using namespace std;

#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scs(a) scanf("%s", a)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define ler freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define imprime(x, Y)                              \
  for (int X = 0; X < Y; X++) cerr << x[X] << " "; \
  cerr << endl;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii> > vvii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld pi = acos(-1);
const int MOD = 1e9 + 7;

int main() {
    ll t, k, i, a, b;

    scanf("%lld %lld",&t, &k);

    vector<int> dp(100005,0);
    vector<int> processed(100005,0);

    dp[0] = 1;

    for( i=1; i<k; i++ ) {
        dp[i] = 1;
        processed[i] = (processed[i-1] + dp[i]) % MOD;
    }

    for( i=k; i<=100003; i++ ) {
        dp[i] = (dp[i-1] + dp[i-k]) % MOD;
        processed[i] = (processed[i-1] + dp[i]) % MOD;
    }

    for( i=0; i<t; i++ ) {
        scanf("%lld %lld",&a,&b);
        cout << ((processed[b] - processed[a-1])+1000000007)%1000000007 << endl;
    }

    return 0;
}

// 1490760864018


#include<bits/stdc++.h>

using namespace std;

const int mod = 1000000007;
int n,m;
int memo[100005];

int dp(int i)
{
    if(i == 0)
        return 1;
    if(i <= 0 )
        return 0;
    if(memo[i]!=-1)
        return memo[i];
    int r = dp(i-1) + dp(i-m);
    return memo[i] = r%mod;
}
int main()
{
    int u,v;
    scanf("%d %d",&n,&m);
    memset(memo,-1,sizeof memo);
    dp(100001);
    memo[0] = 0;
    for(int i=1;i<100002;i++)
        memo[i] = (memo[i] + memo[i-1]) %mod;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&u,&v);
        printf("%d\n",(memo[v]- memo[u-1]+mod)%mod);
    }
    return 0;
}
// 1539354968667


//E.cpp

#include <bits/stdc++.h>

using namespace std;

#define maxn 100001
#define Mod 1000000007
#define MOd 100000000000
unsigned long long dp[maxn];
unsigned long long sum[maxn];

int N,K;

void pd(){
	dp[0] = 1;
	//sum[0] = 0;
	for(int i = 1; i < maxn; i++){
		if(i < K){
			dp[i]=1;
		}
		else{
			//if(K == 1)
			dp[i] = ((dp[i-1]) + (dp[i-K]))%Mod;
		}
		//if(i > 1)

	//sum[i] = ((sum[i-1])+(dp[i]))%Mod;
	}
	for(int i = 2; i < maxn; i++){
		dp[i] = (dp[i]+dp[i-1])%Mod;
	}

}

int main(){
	cin >> N >> K;

	pd();
	dp[0] = 0;
	int u,v;
	for(int i = 0; i < N; i++){
		scanf("%d%d",&u,&v);
		//cout << dp[v] << ' ' << dp[u-1] << endl;
		printf("%llu\n", (dp[v]-dp[u-1]+Mod)%Mod);
	}

	return 0;
}
// 1474916960048


#include <bits/stdc++.h>
#define INT long long unsigned int

using namespace std;

int main(){
	vector<INT> as (100010);
	vector<INT> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%llu%llu",&a,&b);
		maximum = max(maximum,a);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<INT> matrix (maximum + 2, 0);
	vector<INT> cummulative (maximum + 2, 0);
	for (INT i = 0; i < k; i++){
		matrix[i] = 1;
		if (i == 0) cummulative[i] = 1;
		else cummulative[i] = matrix[i] + matrix[i-1];
	}
	for (INT i = k; i <= maximum; i++){
	    matrix[i] += matrix[i-1];
		matrix[i] += matrix[i-k];
		cummulative[i] = (cummulative[i-1] + matrix[i]) % 1000000007;
	}

	for (INT i = 0; i < t; i++){
		printf("%llu\n", cummulative[bs[i]] - cummulative[as[i]-1]);
	}

	return 0;
}

// 1506717527890


#include <bits/stdc++.h>
#define INT long long unsigned int

#define MOD 1000000007

using namespace std;

int main(){
	vector<INT> as (100010);
	vector<INT> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%llu%llu",&a,&b);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<INT> matrix (maximum + 2, 0);
	vector<INT> cummulative (maximum + 2, 0);
	for (INT i = 0; i < k; i++){
		matrix[i] = 1;
		if (i == 0) cummulative[i] = 1;
		else cummulative[i] = matrix[i] + matrix[i-1];
	}
	for (INT i = k; i <= maximum; i++){
	    matrix[i] += matrix[i-1];
		matrix[i] += matrix[i-k];
		cummulative[i] = (cummulative[i-1] + matrix[i]);
	}

	for (INT i = 0; i < t; i++){
		printf("%llu\n", (cummulative[bs[i]] - cummulative[as[i]-1]) % MOD);
	}

	return 0;
}

// 1506718280898


#include <bits/stdc++.h>
#define INT int

using namespace std;

int main(){
	vector<int> as (100010);
	vector<int> bs (100010);
	INT t, k;
	cin >> t >> k;

	INT maximum = 0;

	for (INT i = 0 ; i < t; i++){
		INT a, b;
		scanf("%d%d",&a,&b);
		maximum = max(maximum,a);
		maximum = max(maximum,b);
		as[i] = a;
		bs[i] = b;
	}

	vector<INT> p(maximum + 10, 1);
	vector<INT> q(maximum + 10, 0);

	vector<INT>* last;
	vector<INT>* curr;

	last = &p;
	curr = &q;

	vector<vector<INT> > matrix (
		maximum + 2,
		vector<INT>((maximum / k) + 10, 0));
	for (INT f = 0; f <= maximum; f++){
		matrix[f][0] = 1;
	}
	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)
			matrix[0][b] = 1;
		else
			matrix[0][b] = 0;
	}

	vector<INT> total (maximum + 2, 1);
	vector<INT> answers (maximum + 2, 0);

	for (INT b = 0; b <= maximum/k; b++){
		if (b == 0)continue;
		for (INT f = 0; f <= maximum; f++){
			//	cout << (*last)[f] << ' ';
			(*curr)[f] = 0;
			if (f >= k * b){
				for (INT i = 0; i <= f-k; i++){
					// printf("b = %d f = %d i = %d lastfik = %d\n", b, f, i, (*last)[f-i-k]);
					(*curr)[f] += (*last)[f-i-k];
				}
			}
			total[f] += (*curr)[f];
		}
		//	cout << endl;
		swap(curr, last);
	}
	answers[0] = total[0];
//	cout << (*last)[0] << ' ';
	for (INT i  =  1; i <= maximum; i++){
		answers[i] = total[i] + answers[i-1];
		//	cout << (*last)[i] << ' ';
	}
//	cout << endl;

	for (INT i = 0; i < t; i++){
		printf("%d\n", answers[bs[i]] - answers[as[i]-1]);
	}

	return 0;
}

// 1506715902646


//E.cpp

#include <bits/stdc++.h>

using namespace std;

#define maxn 100001
#define Mod 1000000007
long long dp[maxn];
long long sum[maxn];

int N,K;

void pd(){
	dp[0] = 1;
	sum[0] = 0;
	for(int i = 1; i < maxn; i++){
		if(i < K){
			dp[i]++;
			sum[i] = dp[i] + sum[i-1];
		}
		else{
			if(i == 1){
				dp[i] = 2;
				sum[i] = dp[i] + sum[i-1];
			}
			else{
				dp[i] = dp[i-1] + dp[i-2];
				sum[i] = sum[i-1]+ dp[i];
			}
		}
		if(sum[i] > Mod)
			sum[i] = sum[i]%Mod;
	}
}

int main(){
	cin >> N >> K;

	pd();
	int u,v;
	for(int i = 0; i < N; i++){
		scanf("%d%d",&u,&v);
		//if()
		printf("%lld\n", (sum[v] - sum[u-1])%Mod);
	}

	return 0;
}
// 1474726377358


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll t, k, a, b, i, bagi = 1e9 + 7, dp[100006], hasil;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>>  t >> k;

	memset(dp, -1, sizeof(dp));

	for(i = 0; i <= 100000; i++){
		if(i >= k){
			dp[i] = (dp[i - 1] + dp[i - k]) % bagi;
		}
		else{
			dp[i] = 1;
		}
	}

	while(t--){
		cin>> a >> b;
		hasil = 0;

		for(i = a; i <= b; i++){
			(hasil += dp[i]) % bagi;

		}
		cout<< hasil << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll t, k, a, b, i, bagi = 1e9 + 7, dp[100006], hasil;

ll f(ll x){
	if(x == 0){
		return 1;
	}
	else if(dp[x] == -1){
		if(x > k){
			dp[x] = (f(x - 1)) + (f(x - k)) % bagi;
		}
		else{
			dp[x] = f(x - 1) % bagi;
		}
	}
	return dp[x];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>>  t >> k;

	memset(dp, -1, sizeof(dp));

	while(t--){
		cin>> a >> b;
		hasil = 0;

		for(i = a; i <= b; i++){
			hasil += f(i);
			hasil %= bagi;
		}
		cout<< hasil << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll t, k, a, b, i, bagi = 1e9 + 7, dp[100006], hasil, jum[100005];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>> t >> k;

	memset(dp, -1, sizeof(dp));

	for(i = 0; i <= 100000; i++){
		if(i >= k){
			dp[i] = (dp[i - 1] + dp[i - k]) % bagi;
		}
		else{
			dp[i] = 1;
		}
		jum[i] = (jum[i - 1] + dp[i]) % bagi;
	}

	while(t--){
		cin>> a >> b;
		hasil = 0;

		for(i = a; i <= b; i++){
			(hasil += dp[i]) % bagi;

		}
		cout<< hasil << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll t, k, a, b, i, bagi = 1e9 + 7, dp[100006], hasil;

ll f(ll x){
	if(x == 0){
		return 1;
	}
	else if(dp[x] == -1){
		if(x >= k){
			dp[x] = (f(x - 1)) + (f(x - k)) % bagi;
		}
		else{
			dp[x] = f(x - 1) % bagi;
		}
	}
	return dp[x];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>>  t >> k;

	memset(dp, -1, sizeof(dp));

	for(i = 1; i <= 100000; i++){
		dp[i] = f(i);
	}

	while(t--){
		cin>> a >> b;
		hasil = 0;

		for(i = a; i <= b; i++){
			(hasil += dp[i]) % bagi;

		}
		cout<< hasil << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll t, k, a, b, i, bagi = 1e9 + 7, dp[100006], hasil;

ll f(ll x){
	if(x == 0){
		return 1;
	}
	else if(dp[x] == -1){
		if(x >= k){
			dp[x] = (f(x - 1)) + (f(x - k)) % bagi;
		}
		else{
			dp[x] = f(x - 1) % bagi;
		}
	}
	return dp[x];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>>  t >> k;

	memset(dp, -1, sizeof(dp));

	while(t--){
		cin>> a >> b;
		hasil = 0;

		for(i = a; i <= b; i++){
			hasil += f(i);
			hasil %= bagi;
		}
		cout<< hasil << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

long long a, b, dp[1000006], t, k, bagi = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>> t >> k;

	for(int i = 0; i <= 100000; i++){
		if(i >= k){
			dp[i]= (dp[i - 1] + dp[i - k]) % bagi;
		}
		else{
			dp[i] = 1;
		}
	}

	for(int i = 2; i <= 100000; i++){
		(dp[i] += dp[i - 1]) % bagi;
	}
	dp[0] = 0;

	while(t--){
		cin>> a >> b;
		cout<< dp[b] - dp[a - 1] << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll t, k, a, b, i, bagi = 1e9 + 7, dp[1000006], hasil;

ll f(ll x){
	if(x == 0){
		return 1;
	}
	else if(dp[x] == -1){
		if(x - k >= 0){
			dp[x] = (f(x - 1)) + (f(x - k)) % bagi;
		}
		else{
			dp[x] = f(x - 1) % bagi;
		}
	}
	return dp[x];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>>  t >> k;

	memset(dp, -1, sizeof(dp));

	while(t--){
		cin>> a >> b;
		hasil = 0;

		for(i = a; i <= b; i++){
			hasil += f(i);
			hasil %= bagi;
		}
		cout<< hasil << '\n';
	}
}