#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
void solve() {
  int t, k;
  cin >> t >> k;
  long long ans[100000 + 5];
  for (int i = 0; i <= 100000; i++) {
    if (i < k) {
      ans[i] = 1;
      continue;
    }
    ans[i] = (ans[i - 1] + ans[i - k]);
    if (ans[i] > mod) ans[i] -= mod;
  }
  long long pre[100000 + 5];
  pre[0] = ans[0];
  for (int i = 1; i <= 100000; i++) {
    pre[i] = (pre[i - 1] + ans[i]);
    if (pre[i] > mod) pre[i] -= mod;
  }
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long res = (pre[b] - pre[a - 1] + mod) % mod;
    cout << res << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
