#include <bits/stdc++.h>
using namespace std;
int comb[100000] = {0};
int acc[100000] = {0};
int c = 0;
void rec(int start, int fin, int k) {
  if (fin - start + 1 < k) return;
  if (comb[fin - start] != 0) {
    c = (c + comb[fin - start] - 1) % 1000000007;
    return;
  }
  c = (c + 1) % 1000000007;
  if ((fin - start - k + 1) / k >= 1) {
    rec(start + k, fin, k);
  }
  if (fin - start + 1 > k) {
    rec(start + 1, fin, k);
  }
}
int main() {
  int sum = 0, cases, k, a, b;
  cin >> cases >> k;
  c = 1;
  rec(1, 1, k);
  comb[0] = c;
  acc[0] = c;
  for (int i = 2; i <= 100000; i++) {
    c = 1;
    rec(1, i, k);
    comb[i - 1] = c % 1000000007;
    acc[i - 1] = ((acc[i - 2] + comb[i - 1]) % 1000000007);
  }
  while (cases--) {
    cin >> a >> b;
    sum = 0;
    if (a == 1) {
      sum = acc[b - 1];
    } else {
      sum = (acc[b - 1] - acc[a - 2]) % 1000000007;
    }
    if (sum < 0) {
      sum += 1000000007;
    }
    cout << sum << endl;
  }
  return 0;
}
