#include <bits/stdc++.h>
using namespace std;
long long dp[100001];
void solve(long long k) {
  for (long long i = 0; i < k; i++) {
    dp[i] = 1;
  }
  for (long long i = k; i < 100001; i++) {
    dp[i] = (dp[i - 1] + dp[i - k]) % 1000000007;
  }
}
signed main() {
  long long t, k;
  cin >> t >> k;
  solve(k);
  cout << endl;
  long long prefix[100001];
  long long sum = 0;
  long long ind = 0;
  for (long long i : dp) {
    sum = sum + i;
    prefix[ind] = sum;
    ind += 1;
  }
  for (long long i = 0; i < t; i++) {
    long long a, b;
    cin >> a >> b;
    cout << (prefix[b] - prefix[a] + dp[a]) % 1000000007 << endl;
  }
  return 0;
}
