#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
const int mod = 1000000007;
int dp[maxn + 1];
int go(int n, int k) {
  if (n == 0) return 1;
  int& ans = dp[n];
  if (ans != -1) return ans;
  ans = 0;
  ans += go(n - 1, k);
  if (n >= k) ans += go(n - k, k);
  ans %= mod;
  return ans;
}
int main() {
  int t, k;
  cin >> t >> k;
  memset(dp, -1, sizeof(dp));
  go(maxn, k);
  dp[0] = 0;
  for (int i = 1; i <= maxn; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
  }
  for (int i = 0; i < t; i++) {
    int a, b;
    cin >> a >> b;
    cout << ((dp[b] - dp[a - 1]) + mod) % mod << endl;
  }
  return 0;
}
