#include <bits/stdc++.h>
int main() {
  int n, k, a, b;
  long long t[100001] = {1};
  std::scanf("%d%d", &n, &k);
  for (int i(1); i <= 100000; ++i) {
    t[i] = t[i - 1];
    if (k <= i) t[i] += t[i - k];
    t[i] %= 1000000007LL;
  }
  t[0] = 0;
  for (int i(1); i <= 100000; ++i) t[i] = (t[i] + t[i - 1]) % 1000000007LL;
  std::ios::sync_with_stdio(false);
  while (0 < n--) {
    std::scanf("%d%d", &a, &b);
    std::cout << ((t[b] + 1000000007LL - t[a - 1]) % 1000000007LL) << '\n';
  }
  return 0;
}
