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