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