#include <bits/stdc++.h>
using namespace std;
char buf[131072];
int pos(131072);
int gI() {
  int n = 0;
  while (buf[pos] < '0' || buf[pos] > '9') {
    if (++pos >= 131072) cin.read(buf, 131072), pos = 0;
  }
  while (buf[pos] >= '0' && buf[pos] <= '9') {
    n = n * 10 + buf[pos] - '0';
    if (++pos >= 131072) cin.read(buf, 131072), pos = 0;
  }
  return n;
}
int dp[100010], aib[100010];
int t, k, i, a, b;
void ins_aib(int pos, int val) {
  for (; pos <= 100010; pos = pos + (pos & (-pos)))
    aib[pos] = (aib[pos] + val) % 1000000007;
}
int query(int pos) {
  int x = 0;
  for (; pos > 0; pos = pos - (pos & (-pos))) x = (x + aib[pos]) % 1000000007;
  return x;
}
int main() {
  t = gI();
  k = gI();
  dp[k] = 1;
  for (i = 1; i <= 100010 - 2; ++i) {
    if (i > k)
      dp[i] = (dp[i - 1] + dp[i - k]) % 1000000007;
    else
      ++dp[i];
    ins_aib(i, dp[i]);
  }
  for (; t; --t) {
    a = gI();
    b = gI();
    b = query(b);
    a = query(a - 1);
    if (b - a < 0)
      cout << b - a + 1000000007 << '\n';
    else
      cout << b - a << '\n';
  }
  return 0;
}
