#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t, k, a, b, dp[100001], i, m = 1000000007;
  cin >> t >> k;
  for (i = 0; i < k; i++) dp[i] = 1;
  for (i = k; i <= 100001; i++) dp[i] = (dp[i - 1] + dp[i - k]) % m;
  for (i = 1; i <= 100001; i++) dp[i] = (dp[i] + dp[i - 1]) % m;
  while (t--) {
    cin >> a >> b;
    cout << (dp[b] - dp[a - 1] + m) % m << endl;
  }
}
