#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
int t, k;
int dp[100007];
int n = 100001;
int func(int i) {
  if (i == n) return 1;
  if (dp[i] != -1) return dp[i];
  int res = 0;
  if ((i + k) < n) res = (res + func(i + k)) % MOD;
  res = (res + func(i + 1)) % MOD;
  dp[i] = res % MOD;
  return res;
}
int main() {
  cin >> t >> k;
  memset(dp, -1, sizeof(dp));
  func(0);
  int prefix[100005];
  prefix[0] = 0;
  for (int i = 0; i < 100001; i++) {
    prefix[i + 1] = (prefix[i] + dp[n - 2 - i]) % MOD;
  }
  while (t--) {
    int a, b;
    cin >> a >> b;
    int res = prefix[b] - prefix[a - 1];
    res = (res + MOD) % MOD;
    cout << res << "\n";
  }
}
