#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long mod = 1000000007;
long long dp[N];
long long pre[N];
void compute(long long k) {
  dp[0] = 1;
  for (long long i = 1; i <= N; i++) {
    if (i >= k)
      dp[i] = (dp[i - 1] + dp[i - k]) % mod;
    else
      dp[i] = dp[i - 1];
  }
}
int32_t main() {
  memset(dp, 0, sizeof(dp));
  long long t, k;
  cin >> t >> k;
  compute(k);
  dp[0] = 0;
  for (long long i = 1; i <= N; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % mod;
  }
  while (t--) {
    long long a, b;
    cin >> a >> b;
    cout << ((dp[b] - dp[a - 1] + mod) % mod) << endl;
  }
  return 0;
}
