#include <bits/stdc++.h>
using namespace std;
void input() {}
const int N = 1e5 + 4, mod = 1e9 + 7;
int t, k, l, r;
long long dp[N];
int solve(int i = 1e5) {
  if (i < 0) return 0;
  if (i == 0) return 1;
  long long &ret = dp[i];
  if (~ret) return ret;
  ret = solve(i - 1) % mod;
  ret += solve(i - k) % mod;
  return ret % mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  input();
  cin >> t >> k;
  memset(dp, -1, sizeof dp);
  int x = solve();
  dp[0] = 0;
  for (int i = 1; i <= 1e5; i++) dp[i] += dp[i - 1];
  while (t--) {
    cin >> l >> r;
    cout << (dp[r] - dp[l - 1]) % mod << endl;
  }
}
