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