#include <bits/stdc++.h>
const int N = 100000 + 10;
const long long p = 1000000007;
using namespace std;
int t, k, a, b;
long long f[N], sum[N];
int read() {
  int a, f = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  a = c - '0';
  c = getchar();
  while (c >= '0' && c <= '9') {
    a = a * 10 + c - '0';
    c = getchar();
  }
  return a * f;
}
int main() {
  int i;
  t = read();
  k = read();
  for (i = 1; i < k; i++) f[i] = 1;
  f[k] = 2;
  for (i = k + 1; i <= N; i++) f[i] = (f[i - 1] + f[i - k]) % p;
  for (i = 1; i <= N; i++) sum[i] = (sum[i - 1] + f[i] % p);
  while (t--) {
    a = read();
    b = read();
    printf("%lld\n", (sum[b] - sum[a - 1] + p) % p);
  }
  return 0;
}
