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