#include <bits/stdc++.h>
using namespace std;
int main() {
  int numberOfCase;
  cin >> numberOfCase;
  int t;
  cin >> t;
  int a, b;
  int Min = numeric_limits<int>::max();
  int Max = numeric_limits<int>::min();
  vector<pair<int, int> > inputs;
  for (size_t i = 0; i < numberOfCase; i++) {
    cin >> a >> b;
    if (a < Min) {
      Min = a;
    }
    if (b > Max) {
      Max = b;
    }
    inputs.push_back(pair<int, int>(a, b));
  }
  vector<unsigned long long> arr(Max + 1);
  int k = Max;
  for (size_t i = 0; i < t; i++) {
    arr[k] = 1;
    k--;
  }
  for (k; k >= 0; k--) {
    arr[k] = (arr[k + 1] % 1000000007 + arr[k + t] % 1000000007) % 1000000007;
  }
  for (k = Max - 1; k >= 0; k--) {
    arr[k] = (arr[k] % 1000000007 + arr[k + 1] % 1000000007) % 1000000007;
  }
  for (size_t i = 0; i < inputs.size(); i++) {
    cout << (arr[Max - inputs.at(i).second] -
             arr[Max - inputs.at(i).first + 1] + 1000000007) %
                1000000007
         << endl;
  }
  return 0;
}
