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