#include <bits/stdc++.h>
int t, k, st, fin;
unsigned int res[100001], prefix_res[100001];
int main() {
  int i, j, sum = 0;
  scanf("%i", &t);
  scanf("%i", &k);
  for (i = 0; i < k; i++) {
    res[i] = 1;
  }
  for (i = k; i <= 100000; i++) {
    res[i] = (res[i - 1] + res[i - k]) % (1000000000 + 7);
  }
  prefix_res[0] = res[0];
  for (i = 1; i <= 100000; i++) {
    prefix_res[i] = (prefix_res[i - 1] + res[i]) % (1000000000 + 7);
  }
  for (i = 0; i < t; i++) {
    scanf("%i", &st);
    scanf("%i", &fin);
    printf("%u\n", (prefix_res[fin] - prefix_res[st - 1] + (1000000000 + 7)) %
                       (1000000000 + 7));
  }
  return 0;
}
