#include <bits/stdc++.h>
using namespace std;
long long int dp[100002], ans[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, k, i, m = 1e9 + 7;
  cin >> t >> k;
  dp[0] = 1;
  for (i = 1; i < k; i++) dp[i] = 1;
  for (i = k; i <= 100000; i++) {
    dp[i] = (dp[i - 1] + dp[i - k]) % m;
  }
  for (i = 1; i <= 100000; i++) {
    ans[i] = dp[i] + ans[i - 1];
  }
  while (t--) {
    long long int a, b, ans1;
    cin >> a >> b;
    ans1 = (ans[b] - ans[a - 1]) % m;
    cout << ans1 << "\n";
  }
}
