#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = 5e5 + 5, OO = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int t, k, x, y;
int a[N];
long long solve(int n) {
  if (n == 0) return 1;
  if (a[n]) return a[n];
  long long ans = solve(n - 1) % MOD;
  if (n >= k) ans = (ans + solve(n - k) % MOD) % MOD;
  return a[n] = ans;
}
int main() {
  cin >> t >> k;
  solve(100000);
  for (int i = 1; i < N; ++i) a[i] = (a[i] % MOD + a[i - 1] % MOD) % MOD;
  while (t--) {
    cin >> x >> y;
    cout << (a[y] % MOD - a[x - 1] % MOD + MOD) % MOD << endl;
  }
  return 0;
}
