#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0;
  int f = 1;
  char c = getchar();
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    sum = (sum << 3) + (sum << 1) + c - 48;
  return sum * f;
}
const long long m = 1000000007;
long long dp[100002];
long long f[100002];
long long t, k, l, r;
int main() {
  t = read();
  k = read();
  dp[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    dp[i] = dp[i - 1] % m;
    if (i >= k) dp[i] = (dp[i] % m + dp[i - k] % m) % m;
    f[i] = (dp[i] + f[i - 1]);
  }
  for (int i = 1; i <= t; i++) {
    l = read();
    r = read();
    printf("%lld\n", (f[r] - f[l - 1]) % m);
  }
  return 0;
}
