#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, k;
  cin >> t >> k;
  vector<long long> s(100001);
  vector<long long> ps(100001);
  for (long long i = 0; i < k; i++) {
    s[i] = 1;
    ps[i] = i + 1;
  }
  for (long long i = k; i < 100001; i++) {
    s[i] = (s[i - 1] + s[i - k]) % 1000000007;
    ps[i] = (ps[i - 1] + s[i]) % 1000000007;
  }
  for (long long i = 0; i < t; i++) {
    long long a, b;
    cin >> a >> b;
    cout << (ps[b] - ps[a - 1] + 1000000007) % 1000000007 << endl;
  }
}
