#include <bits/stdc++.h>
using namespace std;
long long t, k, dp[100009], a, b;
long long solve(int n) {
  if (n == 0) return 1;
  if (n < 0) return 0;
  if (dp[n] != -1) return dp[n];
  return dp[n] = ((solve(n - 1) + solve(n - k) + 1) % 1000000007 + 1000000007) %
                 1000000007;
}
int main() {
  cin >> t >> k;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < t; i++) {
    cin >> a >> b;
    cout << ((solve(b) - solve(a - 1)) % 1000000007 + 1000000007) % 1000000007
         << endl;
  }
}
