#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)(2e18);
const long double eps = 1e-6;
const unsigned long long infu = (unsigned long long)(1e36);
const long double pi = 3.141592653589793;
const long long mdl = (long long)(1e9) + 7;
long long power(long long a, long long k) {
  if (k == 0) return 1;
  if (k % 2) return power(a, k - 1) * a;
  long long x = power(a, k / 2);
  return x * x;
}
vector<long long> pFunc(string s) {
  long long n = s.length();
  vector<long long> p(n, 0);
  for (long long i = 1; i < n; i++) {
    long long j = p[i - 1];
    while (j && (s[i] != s[j])) j = p[j - 1];
    if (s[i] == s[j]) j++;
    p[i] = j;
  }
  return p;
}
vector<long long> pFunc(string s1, string s2) { return pFunc(s2 + '$' + s1); }
long long gcd(long long a, long long b) {
  while (a && b) {
    a %= b;
    swap(a, b);
  }
  return a + b;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long sumDig(long long x) {
  long long sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> dp((long long)(1e5) + 1), sum((long long)(1e5) + 1);
  long long t, k;
  cin >> t >> k;
  for (long long i = 0; i < k; i++) dp[i] = 1;
  for (long long i = k; i < dp.size(); i++) {
    dp[i] = (dp[i - 1] + dp[i - k]) % mdl;
  }
  sum[0] = dp[0];
  for (long long i = 1; i < sum.size(); i++) {
    sum[i] = (sum[i - 1] + dp[i]) % mdl;
  }
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long ans = (sum[b] - sum[a - 1] + mdl) % mdl;
    cout << ans << endl;
  }
  return 0;
}
