#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int mod = 1e9 + 7;
  long long int f[100000 + 5];
  f[0] = 1;
  for (long long int i = 1; i < 100000 + 5; i++) {
    if (i < k) {
      f[i] = f[i - 1];
    } else {
      f[i] = (f[i - 1] + f[i - k]) % mod;
    }
  }
  for (long long int i = 1; i < 100000 + 5; i++) {
    (f[i] = (f[i] + f[i - 1]) % mod);
  }
  while (n--) {
    long long int a, b;
    cin >> a >> b;
    cout << (f[b] - f[a - 1] + mod) % mod << endl;
  }
  return 0;
}
