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

public class Main {

	static long sx = 0, sy = 0, m = (long) (1e9+7);

	static ArrayList<Integer>[] a;
	static long[] dp;
	static int[] size;
	static long[] farr;
	// static boolean b = true;

	// static TreeMap<Integer, Integer> hm = new TreeMap<>();
	public static PrintWriter out;
	// static ArrayList<pair> p = new ArrayList<>();
	static long[] fact = new long[(int) 1e6];
	static boolean b = false;
	static StringBuilder sb = new StringBuilder();
	static boolean cycle = false;
	static long mod = 998244353;
	static long[] no, col;
	static String s;
	static int ans = 0;
	static HashSet<Long>[] hm;
	static int[] dis;

	public static void main(String[] args) throws IOException {

		// Scanner scn = new Scanner(new BufferedReader(new
		// InputStreamReader(System.in)));

		out = new PrintWriter(System.out);
		Reader scn = new Reader();

		dp = new long[(int) 1e6+1];
		int t = scn.nextInt(), k = scn.nextInt();
		dp[0] = 1;

		for(int i=1; i<dp.length; i++){
			 dp[i] = dp[i-1]+ (i-k>=0?dp[i-k]:0) +1;
			 dp[i]%=m;
		}

		 while(t--!=0){

			  int a = scn.nextInt(), b = scn.nextInt();

			  System.out.println((dp[b]-dp[a-1]+m)%m);

		 }

	}

	// _________________________TEMPLATE_____________________________________________________________

//	public static long lcm(long x, long y) {
//
//		return (x * y) / gcd(x, y);
//	}
//
//	private static long gcd(long x, long y) {
//		if (x == 0)
//			return y;
//
//		return gcd(y % x, x);
//	}

	// static class comp implements Comparator<Integer> {
	//
	// @Override
	// public int compare(Integer o1, Integer o2) {
	// return depth[o2] - depth[o1];
	// }
	//
	// }

	// public static long pow(long a, long b) {
	//
	// if(b<0)return 0;
	// if (b == 0 || b == 1)
	// return (long) Math.pow(a, b);
	//
	// if (b % 2 == 0) {
	//
	// long ret = pow(a, b / 2);
	// ret = (ret % mod * ret % mod) % mod;
	// return ret;
	// }
	//
	// else {
	// return ((pow(a, b - 1) % mod) * a % mod) % mod;
	// }
	// }

	private static class pair implements Comparable<pair> {

		long val, col;

		pair(long a, long b) {

			val = a;
			col = b;
		}

		@Override
		public int compareTo(pair o) {

			if (this.val < o.val)
				return 1;
			else
				return -1;
		}

	}

	private static String reverse(String s) {

		return new StringBuilder(s).reverse().toString();
	}

	public static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[1000000 + 1]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		public int[][] nextInt2DArray(int m, int n) throws IOException {
			int[][] arr = new int[m][n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++)
					arr[i][j] = nextInt();
			}
			return arr;
		}

		public long[][] nextInt2DArrayL(int m, int n) throws IOException {
			long[][] arr = new long[m][n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++)
					arr[i][j] = nextInt();
			}
			return arr;
		}
		// kickstart - Solution
		// atcoder - Main
	}

}


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

public class Main {

	static long sx = 0, sy = 0, m = (long) (1e9+7);

	static ArrayList<Integer>[] a;
	static long[] dp;
	static int[] size;
	static long[] farr;
	// static boolean b = true;

	// static TreeMap<Integer, Integer> hm = new TreeMap<>();
	public static PrintWriter out;
	// static ArrayList<pair> p = new ArrayList<>();
	static long[] fact = new long[(int) 1e6];
	static boolean b = false;
	static StringBuilder sb = new StringBuilder();
	static boolean cycle = false;
	static long mod = 998244353;
	static long[] no, col;
	static String s;
	static int ans = 0;
	static HashSet<Long>[] hm;
	static int[] dis;

	public static void main(String[] args) throws IOException {

		// Scanner scn = new Scanner(new BufferedReader(new
		// InputStreamReader(System.in)));

		out = new PrintWriter(System.out);
		Reader scn = new Reader();

		dp = new long[(int) 1e6+1];
		int t = scn.nextInt(), k = scn.nextInt();
		dp[0] = 1;

		for(int i=1; i<dp.length; i++){
			 dp[i] = dp[i-1]+ (i-k>=0?dp[i-k]:0) +1;
			 dp[i]%=m;
		}

		 while(t--!=0){

			  int a = scn.nextInt(), b = scn.nextInt();

			  System.out.println(dp[b]-dp[a-1]);

		 }

	}

	// _________________________TEMPLATE_____________________________________________________________

//	public static long lcm(long x, long y) {
//
//		return (x * y) / gcd(x, y);
//	}
//
//	private static long gcd(long x, long y) {
//		if (x == 0)
//			return y;
//
//		return gcd(y % x, x);
//	}

	// static class comp implements Comparator<Integer> {
	//
	// @Override
	// public int compare(Integer o1, Integer o2) {
	// return depth[o2] - depth[o1];
	// }
	//
	// }

	// public static long pow(long a, long b) {
	//
	// if(b<0)return 0;
	// if (b == 0 || b == 1)
	// return (long) Math.pow(a, b);
	//
	// if (b % 2 == 0) {
	//
	// long ret = pow(a, b / 2);
	// ret = (ret % mod * ret % mod) % mod;
	// return ret;
	// }
	//
	// else {
	// return ((pow(a, b - 1) % mod) * a % mod) % mod;
	// }
	// }

	private static class pair implements Comparable<pair> {

		long val, col;

		pair(long a, long b) {

			val = a;
			col = b;
		}

		@Override
		public int compareTo(pair o) {

			if (this.val < o.val)
				return 1;
			else
				return -1;
		}

	}

	private static String reverse(String s) {

		return new StringBuilder(s).reverse().toString();
	}

	public static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[1000000 + 1]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		public int[][] nextInt2DArray(int m, int n) throws IOException {
			int[][] arr = new int[m][n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++)
					arr[i][j] = nextInt();
			}
			return arr;
		}

		public long[][] nextInt2DArrayL(int m, int n) throws IOException {
			long[][] arr = new long[m][n];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++)
					arr[i][j] = nextInt();
			}
			return arr;
		}
		// kickstart - Solution
		// atcoder - Main
	}

}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		int k=s.nextInt();
		int n=100001;
		long dp[][]=new long[n][2];
		dp[0][0]=1;
		long total[]=new long[n+1];
		for(int i=1;i<n;i++)
	    {
	        dp[i][0]=(dp[i][0]+(dp[i-1][1]+dp[i-1][0])%1000000007)%1000000007;
	        if(i-k>=0)
	        dp[i][1]=(dp[i][1]+(dp[i-k][1]+dp[i-k][0])%1000000007)%1000000007;
	        total[i]=((total[i]+total[i-1])%1000000007+(dp[i][0]+dp[i][1])%1000000007)%1000000007;
	       // System.out.println(i+" "+(total[i]));
	    }
	    while(t-->0)
	    {
	        int a=s.nextInt();
	        int b=s.nextInt();
	        System.out.println(total[b]-total[a-1]);
	    }
	}
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		int k=s.nextInt();
		int n=100005;
		long dp[][]=new long[n][2];
		dp[0][0]=1;
		long total[]=new long[n+1];
		for(int i=1;i<n;i++)
	    {
	        dp[i][0]=(dp[i][0]+(dp[i-1][1]+dp[i-1][0]));
	        if(i-k>=0)
	        dp[i][1]=(dp[i][1]+(dp[i-k][1]+dp[i-k][0]));
	        total[i]=(total[i-1]%1000000007+(dp[i][0]+dp[i][1])%1000000007)%1000000007;
	       // System.out.println(i+" "+(total[i]));
	    }
	    while(t-->0)
	    {
	        int a=s.nextInt();
	        int b=s.nextInt();
	        System.out.println(total[b]-total[a-1]);
	    }
	}
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		int k=s.nextInt();
		int n=100005;
		long dp[][]=new long[n][2];
		dp[0][0]=1;
		long total[]=new long[n+1];
		for(int i=1;i<n;i++)
	    {
	        dp[i][0]=(dp[i][0]+(dp[i-1][1]+dp[i-1][0])%1000000007)%1000000007;
	        if(i-k>=0)
	        dp[i][1]=(dp[i][1]+(dp[i-k][1]+dp[i-k][0])%1000000007)%1000000007;
	        total[i]=(total[i-1]%1000000007+(dp[i][0]+dp[i][1])%1000000007)%1000000007;
	       // System.out.println(i+" "+(total[i]));
	    }
	    while(t-->0)
	    {
	        int a=s.nextInt();
	        int b=s.nextInt();
	        System.out.println(((total[b]%1000000007-total[a-1]%1000000007)+1000000007)%1000000007);
	    }
	}
}


/*
 *created by Kraken on 14-04-2020 at 01:42
 */
//package com.kraken.cf.practice;

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

public class D474 {
    static final int MAXN = 100001;
    static final int MOD = (int) 1e9 + 7;
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int t = sc.nextInt(), k = sc.nextInt();
        long[] dp = new long[MAXN];
        dp[0] = 1;
        for (int i = 1; i < MAXN; i++) {
            if (i < k) dp[i] = 1;
            else dp[i] = (dp[i - 1] + dp[i - k]) % MOD;
        }
        long[] sum = new long[MAXN];
        for (int i = 1; i < MAXN; i++) sum[i] = (sum[i - 1] + dp[i]) % MOD;
        while (t-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt();
            System.out.println(sum[b] - sum[a - 1]);
        }
    }

    static class FastReader {

        BufferedReader br;

        StringTokenizer st;

        public FastReader() {
            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;
        }
    }
}


/*
 *created by Kraken on 14-04-2020 at 01:42
 */
//package com.kraken.cf.practice;

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

public class D474 {
    static final int MAXN = 100001;
    static final int MOD = (int) 1e9 + 7;
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int t = sc.nextInt(), k = sc.nextInt();
        long[] dp = new long[MAXN];
        dp[0] = 1;
        for (int i = 1; i < MAXN; i++) {
            if (i < k) dp[i] = 1;
            else dp[i] = (dp[i - 1] + dp[i - k]) % MOD;
        }
        long[] sum = new long[MAXN];
        for (int i = 1; i < MAXN; i++) sum[i] = (sum[i - 1] + dp[i]) % MOD;
        StringBuilder sb = new StringBuilder();
        while (t-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt();
            long res = sum[b] - sum[a - 1];
            if (res < 0) res += MOD;
            sb.append(res + "\n");
        }
        System.out.print(sb.toString());
    }

    static class FastReader {

        BufferedReader br;

        StringTokenizer st;

        public FastReader() {
            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;
        }
    }
}


/*
 *created by Kraken on 14-04-2020 at 01:42
 */
//package com.kraken.cf.practice;

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

public class D474 {
    static final int MAXN = 100001;
    static final int MOD = (int) 1e9 + 7;
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int t = sc.nextInt(), k = sc.nextInt();
        long[] dp = new long[MAXN];
        dp[0] = 1;
        for (int i = 1; i < MAXN; i++) {
            if (i < k) dp[i] = 1;
            else dp[i] = (dp[i - 1] + dp[i - k]) % MOD;
        }
        long[] sum = new long[MAXN];
        for (int i = 1; i < MAXN; i++) sum[i] = (sum[i - 1] + dp[i]) % MOD;
        while (t-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt();
            long res = sum[b] - sum[a - 1];
            if (res < 0) res += MOD;
            System.out.println(res);
        }
    }

    static class FastReader {

        BufferedReader br;

        StringTokenizer st;

        public FastReader() {
            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;
        }
    }
}


// Imports
import java.util.*;
import java.io.*;

public class D474 {

    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {

        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        /* BufferedReader f = new BufferedReader(new StringReader("3 2\n" +
"1 3\n" +
"2 3\n" +
"4 4")); */

        // TODO code application logic here
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        long MOD = (long)1E9 + 7;

        long[] ways = new long[100001];
        ways[0] = 1;
        for(int i = 1; i <= 100000; i++) {
            if(i >= k) {
                ways[i] += ways[i - k]%MOD;
            }
            ways[i] += ways[i - 1]%MOD;
        }

        for(int i = 1; i <= 100000; i++) {
            ways[i] += ways[i - 1];
        }

        // System.out.println(Arrays.toString(ways));

        for(int i = 0; i < n; i++) {
            StringTokenizer query = new StringTokenizer(f.readLine());
            int start = Integer.parseInt(query.nextToken());
            int end = Integer.parseInt(query.nextToken());

            if(ways[end] < ways[start - 1]) {
                System.out.println(ways[end] - ways[start - 1] + MOD);
            }
            else {
                System.out.println(ways[end] - ways[start - 1]);
            }
        }
    }

}


// Imports
import java.util.*;
import java.io.*;

public class D474 {

    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {

        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        /* BufferedReader f = new BufferedReader(new StringReader("3 2\n" +
"1 3\n" +
"2 3\n" +
"4 4")); */

        // TODO code application logic here
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        long MOD = (long)1E9 + 7;

        long[] ways = new long[10001];
        ways[0] = 1;
        for(int i = 1; i <= 10000; i++) {
            if(i >= k) {
                ways[i] += ways[i - k]%MOD;
            }
            ways[i] += ways[i - 1]%MOD;
        }

        for(int i = 1; i <= 10000; i++) {
            ways[i] += ways[i - 1];
        }

        // System.out.println(Arrays.toString(ways));

        for(int i = 0; i < n; i++) {
            StringTokenizer query = new StringTokenizer(f.readLine());
            int start = Integer.parseInt(query.nextToken());
            int end = Integer.parseInt(query.nextToken());

            if(ways[end] < ways[start - 1]) {
                System.out.println(ways[end] - ways[start - 1] + MOD);
            }
            else {
                System.out.println(ways[end] - ways[start - 1]);
            }
        }
    }

}


// Imports
import java.util.*;
import java.io.*;

public class D474 {

    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {

        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        /* BufferedReader f = new BufferedReader(new StringReader("3 2\n" +
"1 3\n" +
"2 3\n" +
"4 4")); */

        // TODO code application logic here
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        long MOD = (long)1E9 + 7;

        long[] ways = new long[100001];
        ways[0] = 1;
        for(int i = 1; i <= 100000; i++) {
            if(i >= k) {
                ways[i] += ways[i - k]%MOD;
            }
            ways[i] += ways[i - 1]%MOD;
        }

        for(int i = 1; i <= 100000; i++) {
            ways[i] += ways[i - 1];
        }

        // System.out.println(Arrays.toString(ways));

        for(int i = 0; i < n; i++) {
            StringTokenizer query = new StringTokenizer(f.readLine());
            int start = Integer.parseInt(query.nextToken());
            int end = Integer.parseInt(query.nextToken());

            if(ways[end] < ways[start - 1]) {
                System.out.println((ways[end] - ways[start - 1] + MOD)%MOD);
            }
            else {
                System.out.println((ways[end] - ways[start - 1])%MOD);
            }
        }
    }

}


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

public class Solution {
	static class Reader {
		BufferedReader br;
		StringTokenizer st;

		public Reader() {
			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;
		}
	}

	static int k;
	static long[] dp = new long[100002];

	public static void main(String[] args) {
		Reader r = new Reader();

		int t = r.nextInt();
		k = r.nextInt();

		//		dp[1] = 1;
		//		recur(10001);

		dp[0] = 1;
		for (int i = 0; i < 100002; i++) {
			dp[i] %= 1000000007;

			if (i < 100002 - k) {
				dp[i + 1] += dp[i];
				dp[i + k] += dp[i];
			} else if (i < 100002 - 1) {
				dp[i + 1] += dp[i];
			}
		}

//		for (int i = 0; i < 10; i++) {
//			System.out.println(dp[i]);
//		}

		for (int i = 2; i < 100002; i++) {
			dp[i] += dp[i - 1];
			dp[i] = dp[i] % 1000000007;
		}

		dp[0] = 0;
//				System.out.println();
//				for (int i = 0; i < 10; i++) {
//					System.out.println(dp[i]);
//				}

		for (int i = 0; i < t; i++) {
			int a = r.nextInt();
			int b = r.nextInt();

			System.out.println(dp[b] - dp[a - 1]);
		}
	}

	static long recur(int i) {
		//		System.out.println("i" + i);

		if (i < 0) {
			return 0;
		} else if (i == 0) {
			return 1;
		} else if (i < 2) {
			if (k == 1) {
				return 2;
			}
			return 1;
		} else if (dp[i] != 0){
			return dp[i];
		} else {
			dp[i] = recur(i - 1) + recur(i - k);
			dp[i] = dp[i] % 1000000007;

			return dp[i];
		}
	}
}


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

public class Solution {
	static class Reader {
		BufferedReader br;
		StringTokenizer st;

		public Reader() {
			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;
		}
	}

	static int k;
	static long[] dp = new long[100002];

	public static void main(String[] args) {
		Reader r = new Reader();

		int t = r.nextInt();
		k = r.nextInt();

		dp[0] = 1;
		for (int i = 0; i < 100002; i++) {
			dp[i] %= 1000000007;

			if (i < 100002 - k) {
				dp[i + 1] += dp[i];
				dp[i + k] += dp[i];
			} else if (i < 100002 - 1) {
				dp[i + 1] += dp[i];
			}
		}

		//		for (int i = 0; i < 10; i++) {
		//			System.out.println(dp[i]);
		//		}

		for (int i = 2; i < 100002; i++) {
			dp[i] += dp[i - 1];
			dp[i] %= 1000000007;
		}

		dp[0] = 0;
		//				System.out.println();
		//				for (int i = 0; i < 10; i++) {
		//					System.out.println(dp[i]);
		//				}

		for (int i = 0; i < t; i++) {
			int a = r.nextInt();
			int b = r.nextInt();

			if (dp[b] < dp[a - 1]) {
				System.out.println((dp[b] - dp[a - 1] + 1000000007) % 1000000007);
			} else {
				System.out.println(dp[b] - dp[a - 1]);
			}
		}
	}

	static long recur(int i) {
		//		System.out.println("i" + i);

		if (i < 0) {
			return 0;
		} else if (i == 0) {
			return 1;
		} else if (i < 2) {
			if (k == 1) {
				return 2;
			}
			return 1;
		} else if (dp[i] != 0){
			return dp[i];
		} else {
			dp[i] = recur(i - 1) + recur(i - k);
			dp[i] = dp[i] % 1000000007;

			return dp[i];
		}
	}
}


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

public class Solution {
	static class Reader {
		BufferedReader br;
		StringTokenizer st;

		public Reader() {
			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;
		}
	}

	static int k;
	static long[] dp = new long[100002];

	public static void main(String[] args) {
		Reader r = new Reader();

		int t = r.nextInt();
		k = r.nextInt();

		dp[0] = 1;
		for (int i = 0; i < 100002; i++) {
			dp[i] %= 1000000007;

			if (i < 100002 - k) {
				dp[i + 1] += dp[i];
				dp[i + k] += dp[i];
				dp[i + 1] %= 1000000007;
				dp[i + k] %= 1000000007;
			} else if (i < 100002 - 1) {
				dp[i + 1] += dp[i];
				dp[i + 1] %= 1000000007;
			}
		}

//		for (int i = 0; i < 10; i++) {
//			System.out.println(dp[i]);
//		}

		for (int i = 2; i < 100002; i++) {
			dp[i] += dp[i - 1];
			dp[i] %= 1000000007;
		}

		dp[0] = 0;
//				System.out.println();
//				for (int i = 0; i < 10; i++) {
//					System.out.println(dp[i]);
//				}

		for (int i = 0; i < t; i++) {
			int a = r.nextInt();
			int b = r.nextInt();

			System.out.println(dp[b] - dp[a - 1]);
		}
	}

	static long recur(int i) {
		//		System.out.println("i" + i);

		if (i < 0) {
			return 0;
		} else if (i == 0) {
			return 1;
		} else if (i < 2) {
			if (k == 1) {
				return 2;
			}
			return 1;
		} else if (dp[i] != 0){
			return dp[i];
		} else {
			dp[i] = recur(i - 1) + recur(i - k);
			dp[i] = dp[i] % 1000000007;

			return dp[i];
		}
	}
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 0;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] = 2 + dp[i - k] + dp[i - 1];

            else
            dp[i] = 1 + dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        static long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k] % mod + dp[i - 1]%mod)%mod;

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1]%mod + dp[i]%mod)%mod;
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        int dp[] = new int[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] = dp[i - k] + dp[i - 1];

            else
            dp[i] = dp[i - 1];
        }
        int sumdp[] = new int[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0]]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] = dp[i - k] + dp[i - 1];

            else
            dp[i] = dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
         long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k] % mod + dp[i - 1]%mod)%mod;

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1]%mod + dp[i]%mod)%mod;
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        static long mod = 1000000007;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k] % mod + dp[i - 1]%mod)%mod;

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1]%mod + dp[i]%mod)%mod;
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        int dp[] = new int[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] = dp[i - k] + dp[i - 1];

            else
            dp[i] = dp[i - 1];
        }
        int sumdp[] = new int[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0]);

            else
            System.out.println(sumdp[queries[i][1]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
         long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k] + dp[i - 1]);

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1] + dp[i]);
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println((sumdp[queries[i][1]] - sumdp[queries[i][0] - 1])%mod);

            else
            System.out.println(sumdp[queries[i][1]]%mod);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
         long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k]%mod + dp[i - 1]%mod)%mod;

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1]%mod + dp[i]%mod)%mod;
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            {

            long ans = ((sumdp[queries[i][1]] - sumdp[queries[i][0] - 1])%mod);
            if(ans < 0)
            System.out.println(ans + mod);
            }

            else
            System.out.println(sumdp[queries[i][1]]%mod);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
         long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k]%mod + dp[i - 1]%mod)%mod;

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1]%mod + dp[i]%mod)%mod;
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            {

            long ans = ((sumdp[queries[i][1]] - sumdp[queries[i][0] - 1])%mod);

            if(ans < 0)
            System.out.println(ans + mod);

            else
            System.out.println(ans);
            }

            else
            System.out.println(sumdp[queries[i][1]]%mod);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  dp[i - k] + dp[i - 1];

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
         long mod = 1000000007;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  (dp[i - k]%mod + dp[i - 1]%mod)%mod;

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = (sumdp[i - 1]%mod + dp[i]%mod)%mod;
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println((sumdp[queries[i][1]] - sumdp[queries[i][0] - 1])%mod);

            else
            System.out.println(sumdp[queries[i][1]]%mod);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        int dp[] = new int[max + 1];
        dp[0] = 1;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] = dp[i - k] + dp[i - 1];

            else
            dp[i] = dp[i - 1];
        }
        int sumdp[] = new int[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


import java.util.*;

public class Solution
{
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int queries[][] = new int[n][2];

        int max = 0;
        for(int i = 0 ; i < n ; i++)
        {
            queries[i][0] = sc.nextInt();
            queries[i][1] = sc.nextInt();

            max = Math.max(max , Math.max(queries[i][0] , queries[i][1]));
        }
        long dp[] = new long[max + 1];
        dp[0] = 0;
        for(int i = 1 ; i <= max ; i++)
        {
            if(i - k >= 0)
            dp[i] =  dp[i - k] + dp[i - 1];

            else
            dp[i] =  dp[i - 1];
        }
        long sumdp[] = new long[max + 1];
        sumdp[1] = dp[1];
        for(int i = 2 ; i <= max ; i++)
        {
            sumdp[i] = sumdp[i - 1] + dp[i];
        }

        for(int i = 0 ; i < n ; i++)
        {
            if(queries[i][0] != 1)
            System.out.println(sumdp[queries[i][1]] - sumdp[queries[i][0] - 1]);

            else
            System.out.println(sumdp[queries[i][1]]);
        }

    }
}


// package test;
import java.io.*;

public class Testr {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] s = new String[2] ;
		int t,k,mod ;
		s = br.readLine().split(" ") ;

		t = Integer.parseInt(s[0]) ;
		k = Integer.parseInt(s[1]) ;
		mod = 1000000007 ;

		while (t>0)
		{
			t--;
			String m[] = new String[2];
			int a,b;
			m = br.readLine().split(" ") ;
			a = Integer.parseInt(m[0]) ;
			b = Integer.parseInt(m[1]) ;

			int[] dp = new int[b+1];
			for (int i = 1 ; i <= b ; i++)
			{
				if (i < k) dp[i] = 1;
				else if (i == k) dp[i] = 2;
				else {
					dp[i] = dp[i-1] + dp[i-k];
				}
			}
			int res = 0;
			for (int j = a ; j <= b ; j++) {
				res += dp[j];
				res %= mod;
			}
			if(res < 0 ) res+= mod;
			System.out.println(res%mod);
		}

	}

}


import java.io.*;

public class Testr {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s[] = new String[2] ;
		s = br.readLine().split(" ") ;
		int t = Integer.parseInt(s[0]) ,
			k = Integer.parseInt(s[1]) ;

		int dp[] = new int[100001];
		int mod = 1000000007;
		for (int i = 1 ; i < dp.length ; i++)
		{
			if (i < k) dp[i] = 1;
			else if (i == k) dp[i] = 2;
			else {
				dp[i] = dp[i-1] ;
				dp[i] %= mod ;
				if (i - k >= 0)
				{
					dp[i] += dp[i-k];
					dp[i] %= mod;
				}
			}
		}
		while (t>0)
		{
			t--;
			String m[] = new String[2] ;
			m = br.readLine().split(" ");
			int a = Integer.parseInt(m[0]) ,
				b = Integer.parseInt(m[1]);
			int res = 0;
			for (int j = a ; j <= b ; j++) {
				res += dp[j];
				res %= mod;
			}
			if(res < 0 ) res+= mod;
			System.out.println(res%mod);
		}

		}

	}


import java.io.*;

public class Testr {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] s = new String[2] ;
		int t,k ;
		s = br.readLine().split(" ") ;

		t = Integer.parseInt(s[0]) ;
		k = Integer.parseInt(s[1]) ;

		while (t>0)
		{
			t--;
			String m[] = new String[2];
			int a,b;
			m = br.readLine().split(" ") ;
			a = Integer.parseInt(m[0]) ;
			b = Integer.parseInt(m[1]) ;

			int[] dp = new int[b+1];
			for (int i = 1 ; i <= b ; i++)
			{
				if (i < k) dp[i] = 1;
				else if (i == k) dp[i] = 2 ;
				else if ( i > k)
				{
					if (i%k == 0) dp[i] = dp[i-1] + 2 ;
					else dp[i] = dp[i-1] + 1;
				}
			}
			int res = 0;
			for (int j = a ; j <= b ; j++) {
				res += dp[j];
			}
			System.out.println(res);
		}

	}

}


// package test;
import java.io.*;

public class Testr {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] s = new String[2] ;
		int t,k,mod ;
		s = br.readLine().split(" ") ;

		t = Integer.parseInt(s[0]) ;
		k = Integer.parseInt(s[1]) ;
		mod = 1000000007 ;

		while (t>0)
		{
			t--;
			String m[] = new String[2];
			int a,b;
			m = br.readLine().split(" ") ;
			a = Integer.parseInt(m[0]) ;
			b = Integer.parseInt(m[1]) ;

			int[] dp = new int[b+1];
			for (int i = 1 ; i <= b ; i++)
			{
				if (i < k) dp[i] = 1;
				else if (i == k) dp[i] = 2;
				else {
					dp[i] = dp[i-1] ;
					dp[i] %= mod ;
					if (i - k >= 0)
					{
						dp[i] += dp[i-k];
						dp[i] %= mod;
					}
				}
			}
			int res = 0;
			for (int j = a ; j <= b ; j++) {
				res += dp[j];
				res %= mod;
			}
			if(res < 0 ) res+= mod;
			System.out.println(res%mod);
		}

	}

}


// package test;
import java.io.*;

public class Testr {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s[] = new String[2] ;
		s = br.readLine().split(" ") ;
		int t = Integer.parseInt(s[0]) ,
			k = Integer.parseInt(s[1]) ;

		int dp[] = new int[100001];
		int mod = 1000000007;
		for (int i = 0 ; i < dp.length ; i++)
		{
			if (i < k) dp[i] = 1;
			else if (i == k) dp[i] = 2;
			else {
				dp[i] = dp[i-1] ;
				if (i - k >= 0)
				{
					dp[i] += dp[i-k];
					dp[i] %= mod;
				}
			}
		}
		for( int i = 1 ; i < dp.length ; i++)
		{
			dp[i] += dp[i-1] ;
			dp[i] %= mod ;
		}

		while (t>0)
		{
			t--;
			String m[] = new String[2] ;
			m = br.readLine().split(" ");
			int a = Integer.parseInt(m[0]) ,
				b = Integer.parseInt(m[1]);
			int res = 0;
			res = dp[b] - dp[a-1] ;
			if(res < 0 ) res+= mod;
			System.out.println(res%mod);
		}

		}

	}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Flowers
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public int gcd(int a, int b) {
        if (b==0) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        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;
        }
    }

    static int M = (int)(1e9+7);
    static int N = (int)(1e5+5);
    static long fact[] = new long[N+1];
    static long inv_fact[] = new long[N+1];
    static long inv[] = new long[N+1];
    static void initialise(){
        fact[0]=fact[1]=1;
        inv_fact[0] =inv_fact[1] = 1;
        inv[0] = inv[1] = 1;
        for(int i=2;i<=N;i++){
            inv[i] = ((inv[M%i])*(M-M/i))%M;
            fact[i] = (i*fact[i-1])%M;
        }
        for(int i=2;i<=N;i++){
            inv_fact[i] = (inv[i]*inv_fact[i-1])%M;
        }

    }

    public static long ncr(int n,int r){
        long ans = (((fact[n]*inv_fact[r])%M)*inv_fact[n-r])%M;
        return ans;
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
//        initialise();

        int t = s.nextInt();
        int k = s.nextInt();
        init(k);
        for(int tt=0;tt<t;tt++){
            int a = s.nextInt();
            int b = s.nextInt();
            long ans = (dp[b+1] - dp[a])%M;
            if(ans<0){
                ans+=M;
            }
            System.out.println(ans);
        }

    }
//    public static long solve(int a,int b,int k){
//        long ans =0;
//        for(int x=0;x*(k-1)<=(b+1);x++){
//            if((b-x*(k-1)+1)>=((x+1))){
//                ans  = (ans+ncr((b-x*(k-1)+1),x+1))%M;
//            }
//            else {
//                break;
//            }
//        }
//        for(int x=0;x*(k-1)<=a;x++){
//            if((a-1-x*(k-1)+1)>=((x+1))){
//                ans= (ans-ncr((a-1-x*(k-1)+1),x+1))%M;
//            }
//            else {
//                break;
//            }
//        }
//        if(ans<0){
//            ans+=M;
//        }
//        return ans;
//    }
    static long[] dp = new long[(int)(1e5+6)];
    public static void init(int k){
        dp[0] = 1;
        for(int i=1;i<k;i++){
            dp[i] = 1;
        }
        for(int i=k;i<=(1e5+5);i++){
            dp[i] = (dp[i-1]+dp[i-k])%M;
        }
        //now caluculate pref_sum;
        for(int i=1;i<=(1e5+5);i++){
            dp[i] = (dp[i]+dp[i-1])%M;
        }
    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//    out.write((arr[i]+" ").getBytes());
//}
//        out.flush();

    //  long start = System.currentTimeMillis();
//  long end = System.currentTimeMillis();
//  System.out.println((end - start) + "ms");

}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Flowers
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public int gcd(int a, int b) {
        if (b==0) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        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;
        }
    }

    static int M = (int)(1e9+7);
    static int N = (int)(1e5+5);
    static long fact[] = new long[N+1];
    static long inv_fact[] = new long[N+1];
    static long inv[] = new long[N+1];
    static void initialise(){
        fact[0]=fact[1]=1;
        inv_fact[0] =inv_fact[1] = 1;
        inv[0] = inv[1] = 1;
        for(int i=2;i<=N;i++){
            inv[i] = ((inv[M%i])*(M-M/i))%M;
            fact[i] = (i*fact[i-1])%M;
        }
        for(int i=2;i<=N;i++){
            inv_fact[i] = (inv[i]*inv_fact[i-1])%M;
        }

    }

    public static long ncr(int n,int r){
        long ans = (((fact[n]*inv_fact[r])%M)*inv_fact[n-r])%M;
        return ans;
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
//        initialise();

        int t = s.nextInt();
        int k = s.nextInt();
        init(k);
        for(int tt=0;tt<t;tt++){
            int a = s.nextInt();
            int b = s.nextInt();
            long ans = (dp[b+1] - dp[a])%M;
            if(ans<0){
                ans+=M;
            }
            System.out.println(ans);
        }

    }
//    public static long solve(int a,int b,int k){
//        long ans =0;
//        for(int x=0;x*(k-1)<=(b+1);x++){
//            if((b-x*(k-1)+1)>=((x+1))){
//                ans  = (ans+ncr((b-x*(k-1)+1),x+1))%M;
//            }
//            else {
//                break;
//            }
//        }
//        for(int x=0;x*(k-1)<=a;x++){
//            if((a-1-x*(k-1)+1)>=((x+1))){
//                ans= (ans-ncr((a-1-x*(k-1)+1),x+1))%M;
//            }
//            else {
//                break;
//            }
//        }
//        if(ans<0){
//            ans+=M;
//        }
//        return ans;
//    }
    static long[] dp = new long[(int)(1e5+6)];
    public static void init(int k){
        for(int i=1;i<k;i++){
            dp[i] = 1;
        }
        for(int i=k;i<=(1e5+5);i++){
            dp[i] = (dp[i-1]+dp[i-k])%M;
        }
        //now caluculate pref_sum;
        for(int i=1;i<=(1e5+5);i++){
            dp[i] = (dp[i]+dp[i-1])%M;
        }
    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//    out.write((arr[i]+" ").getBytes());
//}
//        out.flush();

    //  long start = System.currentTimeMillis();
//  long end = System.currentTimeMillis();
//  System.out.println((end - start) + "ms");

}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Flowers
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public int gcd(int a, int b) {
        if (b==0) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        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;
        }
    }

    static int M = (int)(1e9+7);
    static int N = (int)(1e5+5);
    static long fact[] = new long[N+1];
    static long inv_fact[] = new long[N+1];
    static long inv[] = new long[N+1];
    static void initialise(){
        fact[0]=fact[1]=1;
        inv_fact[0] =inv_fact[1] = 1;
        inv[0] = inv[1] = 1;
        for(int i=2;i<=N;i++){
            inv[i] = ((inv[M%i])*(M-M/i))%M;
            fact[i] = (i*fact[i-1])%M;
        }
        for(int i=2;i<=N;i++){
            inv_fact[i] = (inv[i]*inv_fact[i-1])%M;
        }

    }

    public static long ncr(int n,int r){
        long ans = (((fact[n]*inv_fact[r])%M)*inv_fact[n-r])%M;
        return ans;
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        initialise();
        int t = s.nextInt();
        int k = s.nextInt();
        for(int tt=0;tt<t;tt++){
            int a = s.nextInt();
            int b = s.nextInt();
            System.out.println(solve(a,b,k));
        }

    }
    public static long solve(int a,int b,int k){
        long ans =0;
        for(int x=0;x*(k-1)<=(b+1);x++){
            if((b-x*(k-1)+1)>=((x+1))){
                ans  = (ans+ncr((b-x*(k-1)+1),x+1))%M;
            }
            else {
                break;
            }
        }
        for(int x=0;x*(k-1)<=a;x++){
            if((a-1-x*(k-1)+1)>=((x+1))){
                ans= (ans-ncr((a-1-x*(k-1)+1),x+1))%M;
            }
            else {
                break;
            }
        }
        if(ans<0){
            ans+=M;
        }
        return ans;
    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//    out.write((arr[i]+" ").getBytes());
//}
//        out.flush();

    //  long start = System.currentTimeMillis();
//  long end = System.currentTimeMillis();
//  System.out.println((end - start) + "ms");

}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Flowers
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public int gcd(int a, int b) {
        if (b==0) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        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;
        }
    }

    static int M = (int)(1e9+7);
    static int N = (int)(1e5+5);
    static long fact[] = new long[N+1];
    static long inv_fact[] = new long[N+1];
    static long inv[] = new long[N+1];
    static void initialise(){
        fact[0]=fact[1]=1;
        inv_fact[0] =inv_fact[1] = 1;
        inv[0] = inv[1] = 1;
        for(int i=2;i<=N;i++){
            inv[i] = ((inv[M%i])*(M-M/i))%M;
            fact[i] = (i*fact[i-1])%M;
        }
        for(int i=2;i<=N;i++){
            inv_fact[i] = (inv[i]*inv_fact[i-1])%M;
        }

    }

    public static long ncr(int n,int r){
        long ans = (((fact[n]*inv_fact[r])%M)*inv_fact[n-r])%M;
        return ans;
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
//        initialise();

        int t = s.nextInt();
        int k = s.nextInt();
        init(k);
        for(int tt=0;tt<t;tt++){
            int a = s.nextInt();
            int b = s.nextInt();
            long ans = (dp[b] - dp[a-1])%M;
            if(ans<0){
                ans+=M;
            }
            System.out.println(ans);
        }

    }
//    public static long solve(int a,int b,int k){
//        long ans =0;
//        for(int x=0;x*(k-1)<=(b+1);x++){
//            if((b-x*(k-1)+1)>=((x+1))){
//                ans  = (ans+ncr((b-x*(k-1)+1),x+1))%M;
//            }
//            else {
//                break;
//            }
//        }
//        for(int x=0;x*(k-1)<=a;x++){
//            if((a-1-x*(k-1)+1)>=((x+1))){
//                ans= (ans-ncr((a-1-x*(k-1)+1),x+1))%M;
//            }
//            else {
//                break;
//            }
//        }
//        if(ans<0){
//            ans+=M;
//        }
//        return ans;
//    }
    static long[] dp = new long[(int)(1e5+6)];
    public static void init(int k){
        dp[0] = 1;
        for(int i=1;i<k;i++){
            dp[i] = 1;
        }
        for(int i=k;i<=(1e5+5);i++){
            dp[i] = (dp[i-1]+dp[i-k])%M;
        }
        //now caluculate pref_sum;
        for(int i=1;i<=(1e5+5);i++){
            dp[i] = (dp[i]+dp[i-1])%M;
        }
    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//    out.write((arr[i]+" ").getBytes());
//}
//        out.flush();

    //  long start = System.currentTimeMillis();
//  long end = System.currentTimeMillis();
//  System.out.println((end - start) + "ms");

}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Flowers
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public int gcd(int a, int b) {
        if (b==0) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

        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;
        }
    }

    static int M = (int)(1e9+7);
    static int N = (int)(1e5+5);
    static long fact[] = new long[N+1];
    static long inv_fact[] = new long[N+1];
    static long inv[] = new long[N+1];
    static void initialise(){
        fact[0]=fact[1]=1;
        inv_fact[0] =inv_fact[1] = 1;
        inv[0] = inv[1] = 1;
        for(int i=2;i<=N;i++){
            inv[i] = ((inv[M%i])*(M-M/i))%M;
            fact[i] = (i*fact[i-1])%M;
        }
        for(int i=2;i<=N;i++){
            inv_fact[i] = (inv[i]*inv_fact[i-1])%M;
        }

    }

    public static long ncr(int n,int r){
        long ans = (((fact[n]*inv_fact[r])%M)*inv_fact[n-r])%M;
        return ans;
    }

    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        initialise();
        int t = s.nextInt();
        int k = s.nextInt();
        for(int tt=0;tt<t;tt++){
            int a = s.nextInt();
            int b = s.nextInt();
            System.out.println(solve(a,b,k));
        }

    }
    public static long solve(int a,int b,int k){
        long ans =0;
        for(int x=0;x*(k-1)<=(b+1);x++){
            if((b-x*(k-1)+1)>=((x+1))){
                ans  = (ans+ncr((b-x*(k-1)+1),x+1))%M;
            }
        }
        for(int x=0;x*(k-1)<=a;x++){
            if((a-1-x*(k-1)+1)>=((x+1))){
                ans= (ans-ncr((a-1-x*(k-1)+1),x+1))%M;
            }
        }
        if(ans<0){
            ans+=M;
        }
        return ans;
    }

//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//    out.write((arr[i]+" ").getBytes());
//}
//        out.flush();

    //  long start = System.currentTimeMillis();
//  long end = System.currentTimeMillis();
//  System.out.println((end - start) + "ms");

}


//normal
import java.util.*;
import java.lang.*;
import java.io.*;
// String Tokenizer

public class Main {
	public static void main(String[] args) {
		// code
		Scanner scn = new Scanner(System.in);

		int t = scn.nextInt();
		int k = scn.nextInt();
		int M = 1000000007;
		int n = 100001;
		int[] dp = new int[n];
		dp[0] = 1;
		for (int i = 1; i < n; i++) {
			dp[i] = (dp[i] + dp[i - 1]) % M;
			if (i - k >= 0) {
				dp[i] = (dp[i] + dp[i - k]) % M;
			}
		}
		for (int i = 1; i < n; i++) {

			dp[i] = (dp[i] + dp[i - 1]) % M;

		}
		while (t > 0) {
			t--;

			int a = scn.nextInt();
			int b = scn.nextInt();

			System.out.println((dp[b] - dp[a - 1] + M) % M);

		}
	}
}


import java.io.*;
import java.util.*;
public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb = new StringBuilder("");
    private static int mod = (int)1e9 + 7;

    static long[] inputArray(int n) throws IOException {
        long a[] = new long[n];
        st = new StringTokenizer(br.readLine());
        for(int i = 0 ; i < n ; i++) {
            a[i] = Long.parseLong(st.nextToken());
        }
        return a;
    }

    static long[][] inputPoints(int n) throws IOException {
        long[][] a = new long[n][3];
        for(int i = 0 ; i < n ;i++) {
            st = new StringTokenizer(br.readLine());
            a[i][0] = Long.parseLong(st.nextToken());
            a[i][1] = Long.parseLong(st.nextToken());
            a[i][2] = i;
        }
        return a;
    }

    public static void main(String[] args) throws IOException {
        st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int n = (int)1e5;
        long[] dp = createDP(k , n);
        long[] preSum = createPreSum(dp , n);
        while(t-- != 0) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            sb.append((preSum[b] - preSum[a-1] + mod) % mod).append("\n");
        }
        System.out.print(sb);
    }

    private static long[] createPreSum(long[] dp , int n) {
        long[] preSum = new long[n+1];
        preSum[0] = 0;
        for(int i = 1 ; i <= n ; i++) {
            preSum[i] = (preSum[i-1] + dp[i]) % mod;
        }
        return preSum;
    }

    static long[] createDP(int k , int n) {
        long dp[] = new long[n+1];
        dp[0] = 1;
        for(int i = 1 ; i <= n ; i++) {
            if(i >= k) {
                dp[i] = (dp[i] + dp[i-k]) % mod;
            }
            dp[i] = (dp[i] + dp[i-1]) % mod;
        }
        return dp;
    }

}


import java.io.*;
import java.util.*;
public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb = new StringBuilder("");
    private static int mod = (int)1e9 + 7;

    static long[] inputArray(int n) throws IOException {
        long a[] = new long[n];
        st = new StringTokenizer(br.readLine());
        for(int i = 0 ; i < n ; i++) {
            a[i] = Long.parseLong(st.nextToken());
        }
        return a;
    }

    static long[][] inputPoints(int n) throws IOException {
        long[][] a = new long[n][3];
        for(int i = 0 ; i < n ;i++) {
            st = new StringTokenizer(br.readLine());
            a[i][0] = Long.parseLong(st.nextToken());
            a[i][1] = Long.parseLong(st.nextToken());
            a[i][2] = i;
        }
        return a;
    }

    public static void main(String[] args) throws IOException {
        st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int n = (int)1e5;
        long[] dp = createDP(k , n);
        long[] preSum = createPreSum(dp , n);
        while(t-- != 0) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            sb.append((preSum[b] - preSum[a-1]) % mod).append("\n");
        }
        System.out.print(sb);
    }

    private static long[] createPreSum(long[] dp , int n) {
        long[] preSum = new long[n+1];
        preSum[0] = 0;
        for(int i = 1 ; i <= n ; i++) {
            preSum[i] = (preSum[i-1] + dp[i]) % mod;
        }
        return preSum;
    }

    static long[] createDP(int k , int n) {
        long dp[] = new long[n+1];
        dp[0] = 1;
        for(int i = 1 ; i <= n ; i++) {
            if(i >= k) {
                dp[i] = (dp[i] + dp[i-k]) % mod;
            }
            dp[i] = (dp[i] + dp[i-1]) % mod;
        }
        return dp;
    }

}


import java.io.*;
import java.util.*;
public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb = new StringBuilder("");

    static long[] inputArray(int n) throws IOException {
        long a[] = new long[n];
        st = new StringTokenizer(br.readLine());
        for(int i = 0 ; i < n ; i++) {
            a[i] = Long.parseLong(st.nextToken());
        }
        return a;
    }

    static long[][] inputPoints(int n) throws IOException {
        long[][] a = new long[n][3];
        for(int i = 0 ; i < n ;i++) {
            st = new StringTokenizer(br.readLine());
            a[i][0] = Long.parseLong(st.nextToken());
            a[i][1] = Long.parseLong(st.nextToken());
            a[i][2] = i;
        }
        return a;
    }

    public static void main(String[] args) throws IOException {
        st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int n = (int)1e5;
        int[] dp = createDP(k , n);
        long[] preSum = createPreSum(dp , n);
        while(t-- != 0) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            sb.append(preSum[b] - preSum[a-1]).append("\n");
        }
        System.out.print(sb);
    }

    private static long[] createPreSum(int[] dp , int n) {
        int mod = (int)1e9 + 7;
        long[] preSum = new long[n+1];
        preSum[0] = 0;
        for(int i = 1 ; i <= n ; i++) {
            preSum[i] = (preSum[i-1] + dp[i]) % mod;
        }
        return preSum;
    }

    static int[] createDP(int k , int n) {
        int dp[] = new int[n+1];
        dp[0] = 1;
        for(int i = 1 ; i <= n ; i++) {
            if(i >= k) {
                dp[i] += dp[i-k];
            }
            dp[i] += dp[i-1];
        }
        return dp;
    }

}


import java.io.*;
import java.util.*;
public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb = new StringBuilder("");
    private static int mod = (int)1e9 + 7;

    static long[] inputArray(int n) throws IOException {
        long a[] = new long[n];
        st = new StringTokenizer(br.readLine());
        for(int i = 0 ; i < n ; i++) {
            a[i] = Long.parseLong(st.nextToken());
        }
        return a;
    }

    static long[][] inputPoints(int n) throws IOException {
        long[][] a = new long[n][3];
        for(int i = 0 ; i < n ;i++) {
            st = new StringTokenizer(br.readLine());
            a[i][0] = Long.parseLong(st.nextToken());
            a[i][1] = Long.parseLong(st.nextToken());
            a[i][2] = i;
        }
        return a;
    }

    public static void main(String[] args) throws IOException {
        st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int n = (int)1e5;
        long[] dp = createDP(k , n);
        long[] preSum = createPreSum(dp , n);
        while(t-- != 0) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            sb.append((preSum[b] - preSum[a-1]) % mod).append("\n");
        }
        int i =0;
        System.out.print(sb);
    }

    private static long[] createPreSum(long[] dp , int n) {
        long[] preSum = new long[n+1];
        preSum[0] = 0;
        for(int i = 1 ; i <= n ; i++) {
            preSum[i] = (preSum[i-1] + dp[i]) % mod;
        }
        return preSum;
    }

    static long[] createDP(int k , int n) {
        long dp[] = new long[n+1];
        dp[0] = 1;
        for(int i = 1 ; i <= n ; i++) {
            if(i >= k) {
                dp[i] = (dp[i] + dp[i-k]) % mod;
            }
            dp[i] = (dp[i] + dp[i-1]) % mod;
        }
        return dp;
    }

}


import java.io.*;
import java.util.*;
public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb = new StringBuilder("");
    private static int mod = (int)1e9 + 7;

    static long[] inputArray(int n) throws IOException {
        long a[] = new long[n];
        st = new StringTokenizer(br.readLine());
        for(int i = 0 ; i < n ; i++) {
            a[i] = Long.parseLong(st.nextToken());
        }
        return a;
    }

    static long[][] inputPoints(int n) throws IOException {
        long[][] a = new long[n][3];
        for(int i = 0 ; i < n ;i++) {
            st = new StringTokenizer(br.readLine());
            a[i][0] = Long.parseLong(st.nextToken());
            a[i][1] = Long.parseLong(st.nextToken());
            a[i][2] = i;
        }
        return a;
    }

    public static void main(String[] args) throws IOException {
        st = new StringTokenizer(br.readLine());
        int t = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int n = (int)1e5;
        long[] dp = createDP(k , n);
        long[] preSum = createPreSum(dp , n);
        while(t-- != 0) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            sb.append(preSum[b] - preSum[a-1]).append("\n");
        }
        System.out.print(sb);
    }

    private static long[] createPreSum(long[] dp , int n) {
        long[] preSum = new long[n+1];
        preSum[0] = 0;
        for(int i = 1 ; i <= n ; i++) {
            preSum[i] = (preSum[i-1] + dp[i]) % mod;
        }
        return preSum;
    }

    static long[] createDP(int k , int n) {
        long dp[] = new long[n+1];
        dp[0] = 1;
        for(int i = 1 ; i <= n ; i++) {
            if(i >= k) {
                dp[i] = (dp[i] + dp[i-k]) % mod;
            }
            dp[i] = (dp[i] + dp[i-1]) % mod;
        }
        return dp;
    }

}


/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class Flower implements Runnable {
    public static void main(String[] args) throws Exception {
        new Thread(null, new Flower(), ": )", 1 << 28).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int T = sc.nextInt();
        int K = sc.nextInt();
        long[] dp = new long[(int) 1e5 + 1];
        long[] pre = new long[(int) 1e5 + 1];
        dp[0] = 1;
        pre[0] = 1;
        for (int i = 1; i < dp.length; i++) {
            dp[i] = dp[i - 1];
            if (i >= K) {
                dp[i] = (dp[i] + dp[i - K]) % mod;
            }
            pre[i] = (pre[i - 1] + dp[i]) % mod;
        }
        while (T-->0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            out.println(pre[b] - pre[a - 1]);
        }
        out.close();
    }

    static long mod = (long) 1e9 + 7;

    static class FastScanner {
        private int BS = 1 << 16;
        private char NC = (char) 0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt = 1;
            boolean neg = false;
            if (c == NC) c = getChar();
            for (; (c < '0' || c > '9'); c = getChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = getChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                cnt *= 10;
            }
            return neg ? -res : res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c != '.' ? cur : cur + nextLong() / cnt;
        }

        public double[] nextDoubles(int N) {
            double[] res = new double[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextDouble();
            }
            return res;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c > 32) {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c != '\n') {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }

    static void ASSERT(boolean assertion, String message) {
        if (!assertion) throw new AssertionError(message);
    }

    static void ASSERT(boolean assertion) {
        if (!assertion) throw new AssertionError();
    }
}


/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class Flower implements Runnable {
    public static void main(String[] args) throws Exception {
        new Thread(null, new Flower(), ": )", 1 << 28).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int T = sc.nextInt();
        int K = sc.nextInt();
        long[] dp = new long[(int) 1e5 + 1];
        long[] pre = new long[(int) 1e5 + 1];
        dp[0] = 1;
        pre[0] = 1;
        for (int i = 1; i < dp.length; i++) {
            dp[i] = dp[i - 1];
            if (i >= K) {
                dp[i] = (dp[i] + dp[i - K]) % mod;
            }
            pre[i] = (pre[i - 1] + dp[i]) % mod;
        }
        while (T-->0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            out.println((pre[b] - pre[a - 1] + mod) % mod);
        }
        out.close();
    }

    static long mod = (long) 1e9 + 7;

    static class FastScanner {
        private int BS = 1 << 16;
        private char NC = (char) 0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt = 1;
            boolean neg = false;
            if (c == NC) c = getChar();
            for (; (c < '0' || c > '9'); c = getChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = getChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                cnt *= 10;
            }
            return neg ? -res : res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c != '.' ? cur : cur + nextLong() / cnt;
        }

        public double[] nextDoubles(int N) {
            double[] res = new double[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextDouble();
            }
            return res;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c > 32) {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c != '\n') {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }

    static void ASSERT(boolean assertion, String message) {
        if (!assertion) throw new AssertionError(message);
    }

    static void ASSERT(boolean assertion) {
        if (!assertion) throw new AssertionError();
    }
}