#include <bits/stdc++.h>
using namespace std;
bool func(const pair<long long, long long> &a,
          const pair<long long, long long> &b) {
  return a.second < b.second;
}
long long int power(long long int a, long long int b) {
  long long int res = 1;
  a %= 1000000007;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, tmp = 1;
  int k;
  cin >> t;
  cin >> k;
  long long int dp[100010] = {0};
  for (long long int i = 0; i < k - 1; ++i) dp[i + 1] = 1;
  dp[k] = 2;
  for (long long int i = k + 1; i <= 100009; ++i) {
    dp[i] = dp[i - 1] + dp[i - k];
    dp[i] %= 1000000007;
  }
  long long int dpp[100010] = {0};
  for (long long int i = 1; i <= 100009; ++i) {
    dpp[i] = dpp[i - 1] + dp[i];
    dpp[i] %= 1000000007;
  }
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    long long int res = dpp[b] - dpp[a - 1];
    res %= 1000000007;
    cout << (res + 1000000007) % 1000000007;
    if (t) cout << "\n";
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}
