#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
const int INF = 100000000;
long long int n;
vector<long long int> a(N + 1), b(N + 2), c;
void dp(int k) {
  for (long long int i = 0; i < (N + 1); i++) {
    if (i < k) {
      b[i] = 1;
    } else {
      b[i] = b[i - 1] + b[i - k];
      b[i] = b[i] % (1000000000 + 7);
    }
  }
}
void precalc() {
  a[0] = 0;
  for (long long int i = 1; i < (N + 1); i++) {
    a[i] = a[i - 1] + b[i];
    a[i] = a[i] % (1000000000 + 7);
  }
}
void solve() {
  cin >> n;
  int k;
  cin >> k;
  dp(k);
  precalc();
  for (long long int i = 0; i < (n); i++) {
    int x, y;
    cin >> x >> y;
    if (a[x - 1] > a[y]) {
      cout << (1000000000 + 7) + a[y] - a[x - 1];
    } else {
      cout << a[y] - a[x - 1];
    }
    cout << '\n';
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
