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