#include <bits/stdc++.h>
using namespace std;
long long n, k, a[5 * 500001], sum, l, b[5 * 500001], kq, t, dp[5 * 500001],
    mod = 1e9 + 7, d[500001];
int main() {
  cin >> n >> k;
  dp[0] = 1;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  for (long long i = 1; i <= 100005; i++) {
    dp[i] = dp[i - 1];
    d[i] = d[i - 1];
    if (i >= k) dp[i] = (dp[i] + dp[i - k]) % mod;
    d[i] += dp[i];
  }
  for (long long i = 1; i <= n; i++) {
    cout << (d[b[i]] - d[a[i] - 1] + mod) % mod << endl;
  }
}
