#include <bits/stdc++.h>
using namespace std;
long long dp[112345], MOD = 1e9 + 7;
int main() {
  std::ios_base::sync_with_stdio(false);
  int i, j, k, t, K;
  cin >> t >> K;
  dp[0] = 1;
  for (int(i) = 0; (i) < int(112300); ++(i)) {
    dp[i] %= MOD;
    dp[i + 1] += dp[i];
    if (i + K < 112300) dp[i + K] += dp[i];
  }
  for (int(i) = 0; (i) < int(112300); ++(i)) {
    dp[i] %= MOD;
    dp[i + 1] += dp[i];
  }
  int a, b;
  for (int(i) = 0; (i) < int(t); ++(i)) {
    cin >> a >> b;
    a--;
    cout << (MOD + dp[b] - dp[a]) % MOD << endl;
  }
  return 0;
}
