#include <bits/stdc++.h>
using namespace std;
const int N = 200005, mod = 1e9 + 7;
int t, k, a, b;
long long PS[N], A[N];
int main() {
  A[0] = 1;
  scanf("%d %d", &t, &k);
  for (int i = 1; i < 100005; i++) {
    A[i] += A[i - 1];
    A[i] = A[i] % mod;
    if (i >= k) {
      A[i] += A[i - k];
      A[i] = A[i] % mod;
    }
    PS[i] = PS[i - 1] + A[i];
  }
  while (t--) {
    scanf("%d %d", &a, &b);
    cout << (PS[b] - PS[a - 1] + mod) % mod << endl;
  }
}
