#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long int maxN = 1e5 + 10;
const long long int mod = 1e9 + 7;
long long int dp[maxN];
long long int pref[maxN];
signed main() {
  long long int t, k;
  cin >> t >> k;
  dp[0] = 1;
  for (long long int i = 1; i < maxN; i++) {
    dp[i] = dp[i - 1];
    if (i - k >= 0) dp[i] = (dp[i] + dp[i - k]) % mod;
  }
  pref[0] = 1;
  for (long long int i = 1; i < maxN; i++) {
    pref[i] = (pref[i - 1] + dp[i]) % mod;
  }
  for (long long int i = 0; i < t; i++) {
    long long int a, b;
    cin >> a >> b;
    cout << (pref[b] - pref[a - 1] + mod) % mod << "\n";
  }
  return 0;
}
