#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int n = 1e5;
using namespace std;
int main() {
  int q, k;
  cin >> q >> k;
  vector<int> dp(n + 1, 1), pref(n + 1, 1);
  for (int i = 1; i < k; ++i) pref[i] += pref[i - 1];
  for (int i = k; i <= n; ++i) {
    dp[i] = (dp[i - 1] + dp[i - k]) % mod;
    pref[i] = (pref[i - 1] + dp[i]) % mod;
  }
  int a, b;
  for (int i = 0; i < q; ++i) {
    cin >> a >> b;
    cout << (pref[b] - pref[a - 1] + mod) % mod << "\n";
  }
  return 0;
}
