#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, a[100005], b[100005];
  b[0] = 0;
  cin >> n >> k;
  a[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    if (i < k)
      a[i] = 1;
    else
      a[i] = (a[i - 1] + a[i - k]) % 1000000007;
    b[i] = b[i - 1] + a[i];
  }
  long long int c, d;
  while (n--) {
    cin >> c >> d;
    cout << (b[d] - b[c - 1]) % 1000000007 << endl;
  }
}
