#include <bits/stdc++.h>
using namespace std;
void fast() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
int main() {
  fast();
  long long t, k;
  long long mod = 1e9 + 7;
  cin >> t >> k;
  long long dp[100005] = {0};
  long long pre[100005] = {0};
  for (int i = 0; i < k; ++i) {
    dp[i] = 1;
  }
  for (int j = k; j <= 100000; ++j) {
    dp[j] = ((dp[j - 1]) + (dp[j - k]));
    dp[j] %= mod;
  }
  for (int l = 1; l <= 100000; ++l) {
    pre[l] = ((pre[l - 1]) + (dp[l]));
    pre[l] %= mod;
  }
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long ans = pre[b] - pre[a - 1];
    if (ans < 0) ans += mod;
    cout << ans << "\n";
  }
}
