#include <bits/stdc++.h>
using namespace std;
int memo[100007];
int MOD = 1e9 + 7;
long long t, k;
int n = 100001;
long long solve(long long pos) {
  if (pos == n) {
    return 1;
  }
  if (memo[pos] != -1) return memo[pos];
  long long res = 0;
  if ((pos + k) < n) res = (res + solve(pos + k)) % MOD;
  res = (res + solve(pos + 1)) % MOD;
  memo[pos] = res % MOD;
  return res;
}
int main() {
  cin >> t >> k;
  memset(memo, -1, sizeof(memo));
  solve(0);
  long long prefix[100005];
  prefix[0] = 0;
  for (int i = 0; i < 100001; i++) {
    prefix[i + 1] = (prefix[i] + memo[n - 2 - i]) % MOD;
  }
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long res = prefix[b] - prefix[a - 1];
    res = (res + MOD) % MOD;
    cout << res << "\n";
  }
}
