#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7, mod = 1e9 + 7;
long long int dp[maxn];
void solve(int k) {
  dp[0] = 1;
  for (int i = 1; i <= 1e5; i++) {
    if (i < k) {
      dp[i] = dp[i - 1] % mod;
    } else {
      dp[i] = dp[i - 1] + dp[i - k];
      dp[i] %= mod;
    }
  }
  for (int i = 2; i <= 1e5; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
  }
  dp[0] = 0;
}
int main() {
  int t, k;
  cin >> t >> k;
  solve(k);
  while (t--) {
    int a, b;
    cin >> a >> b;
    cout << (dp[b] - dp[a - 1] + mod) % mod << "\n";
  }
}
