#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), b(n);
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    mx = max(mx, b[i]);
  }
  vector<long long> dp(mx + 1), sum(mx + 1);
  dp[0] = 1;
  sum[0] = 1;
  for (long long i = 1; i <= mx; i++) {
    dp[i] = dp[i - 1];
    sum[i] = dp[i];
    if (i - k >= 0) {
      dp[i] = (dp[i] + sum[i - k]) % MOD;
      sum[i] = (sum[i] + sum[i - k]) % MOD;
      dp[i] %= MOD;
      sum[i] %= MOD;
    }
  }
  vector<long long> pref(mx + 1);
  pref[0] = dp[0];
  for (long long i = 1; i <= mx; i++) {
    pref[i] = (pref[i - 1] + dp[i]) % MOD;
  }
  for (long long i = 0; i < n; i++) {
    cout << (pref[b[i]] - pref[a[i] - 1] + MOD) % MOD << '\n';
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long tc = 0; tc < t; tc++) {
    solve();
  }
  return 0;
}
