#include <bits/stdc++.h>
using namespace std;
void input(long long int n, long long int arr[]) {
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> arr[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int> > v(n);
  long long int mx = -INT_MAX;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    cin >> v[i].first >> v[i].second;
    mx = max(mx, v[i].second);
  }
  long long int sum[mx + 1], dp[mx + 1];
  memset(sum, 0, sizeof(sum));
  memset(dp, 0, sizeof(dp));
  for (__typeof(mx + 1) i = (0) - ((0) > (mx + 1));
       i != (mx + 1) - ((0) > (mx + 1)); i += 1 - 2 * ((0) > (mx + 1))) {
    if (i < k)
      dp[i] = 1;
    else {
      dp[i] = (dp[i - 1] + dp[i - k]) % 1000000007;
    }
    if (i > 0) sum[i] = (sum[i - 1] + dp[i]) % 1000000007;
  }
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    cout << (sum[v[i].second] - sum[v[i].first - 1] + 1000000007) % 1000000007
         << endl;
  }
}
