#include <bits/stdc++.h>
using namespace std;
long long const mod = 1e9 + 7;
int const ma = 1e5 + 7;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t, k;
  cin >> t >> k;
  vector<vector<long long>> dp(ma, vector<long long>(2, 0));
  vector<long long> pref(ma, 0);
  dp[0][0] = 1;
  for (int i = 1; i < ma; ++i) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
    if (k <= i) {
      dp[i][1] = (dp[i - k][0] + dp[i - k][1]) % mod;
      ;
    }
    pref[i] = (pref[i - 1] + dp[i][0] + dp[i][1]) % mod;
  }
  while (t--) {
    int a, b;
    cin >> a >> b;
    long long ans = (pref[b] - pref[a - 1]);
    if (ans < 0) {
      ans += mod;
    }
    cout << ans << '\n';
  }
  return 0;
}
