#include <bits/stdc++.h>
using namespace std;
long long oll = 0;
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}
long long mod = 1e9 + 7;
long long dp[100009];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, k;
  cin >> t >> k;
  for (long long i = 0; i < k; i++) dp[i] = 1;
  for (long long i = k; i <= 1e5; i++) dp[i] = (dp[i - 1] + dp[i - k]) % mod;
  for (long long i = 1; i <= 1e5; i++) dp[i] = (dp[i] + dp[i - 1]) % mod;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long ans = (dp[b] - dp[a - 1]);
    if (ans < 0) ans += mod;
    cout << ans << "\n";
  }
  return 0;
}
