#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007, t, pref[200000], dp[200000], k, a, b, q;
int main() {
  cin >> t >> k;
  dp[0] = 1;
  if (k == 1)
    dp[1] = 2;
  else
    dp[1] = 1;
  for (int i = 2; i <= 100001; i++) {
    if (i >= k)
      dp[i] = (dp[i - 1] + dp[i - k]) % mod;
    else
      dp[i] = dp[i - 1] % mod;
  }
  for (int i = 1; i <= 100001; i++) pref[i] = (dp[i] + pref[i - 1]) % mod;
  for (int i = 1; i <= t; i++) {
    cin >> a >> b;
    if (pref[a - 1] > pref[b])
      cout << pref[b] - pref[a - 1] + mod << endl;
    else
      cout << pref[b] - pref[a - 1] << endl;
  }
}
