#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long z = 1000000007;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % z;
      b--;
    } else {
      a = (a * a) % z;
      b = b >> 1;
    }
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, k;
  t = 1;
  cin >> t >> k;
  long long dp[100001] = {0};
  for (long long i = 0; i <= 100000; i++) {
    if (i < k)
      dp[i] = 1;
    else {
      dp[i] = (dp[i - 1] + dp[i - k]);
      dp[i] %= z;
    }
  }
  for (long long i = 1; i <= 100000; i++) dp[i] += dp[i - 1], dp[i] %= z;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long ans = dp[b] - dp[a - 1];
    if (ans < 0) ans += z;
    cout << ans << "\n";
  }
}
