#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
int main() {
  int t, k, a, b, i;
  dp[0] = 1;
  long long MOD = 1000000007;
  cin >> t >> k;
  for (i = 1; i <= 100000; i++) {
    dp[i] = dp[i - 1];
    if (i >= k) dp[i] = (dp[i] + dp[i - k]) % MOD;
  }
  for (i = 1; i <= 100000; i++) dp[i] = (dp[i] + dp[i - 1]) % MOD;
  while (t--) {
    cin >> a >> b;
    cout << (dp[b] - dp[a - 1] + MOD) % MOD << endl;
  }
  return 0;
}
