#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
const int INF = (int)(2e9 + 0.5);
const int MAXN = 100500;
const long long mod = 1000000007;
long long t, k, a, b, dp[MAXN], prefix[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t >> k;
  dp[0] = 1LL;
  for (int i = 1; i < MAXN; ++i) {
    dp[i] += (dp[i - 1]) % mod;
    dp[i] %= mod;
    if (i >= k) {
      dp[i] += (dp[i - k]) % mod;
      dp[i] %= mod;
    }
  }
  prefix[0] = dp[0];
  for (int i = 1; i < MAXN; ++i) {
    prefix[i] = ((prefix[i - 1]) % mod + (dp[i]) % mod) % mod;
    prefix[i] %= mod;
  }
  while (t-- > 0) {
    cin >> a >> b;
    if (a > b) swap(a, b);
    cout << (prefix[b] - prefix[a - 1] + mod) % mod << endl;
  }
  return 0;
}
