#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j, k, m, l;
  cin >> n >> k;
  vector<vector<long long> > dp(1e5 + 1, vector<long long>(2, 0));
  long long mod = 1e9 + 7;
  dp[1][0] = 1;
  dp[0][0] = dp[0][1] = 1;
  if (k == 1) dp[1][1] = 1;
  for (i = 2; i <= 1e5; i++) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
    if (i == k) {
      dp[i][1] = 1;
    } else if (i > k)
      dp[i][1] = (dp[i - k][1] + dp[i - k][0]) % mod;
  }
  long long dpt[(long long)1e5 + (long long)1];
  memset(dpt, 0, sizeof dpt);
  for (i = 1; i <= 1e5; i++) {
    if (i > 1) dpt[i] = dpt[i - 1];
    dpt[i] = (dpt[i] + dp[i][0] + dp[i][1]) % mod;
  }
  while (n--) {
    long long lft, rt;
    cin >> lft >> rt;
    long long ans = (dpt[rt] - dpt[lft - 1] + mod) % mod;
    cout << ans << "\n";
  }
  return 0;
}
