#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int a, b, k, s, t, DP[100001];
int main() {
  cin >> t >> k;
  for (int i = 0; i < k; ++i) {
    DP[i] = 1;
  }
  for (int i = k; i <= 100000; ++i) {
    DP[i] = (DP[i - k] + DP[i - 1]) % MOD;
  }
  for (int i = 1; i <= 100000; ++i) {
    DP[i] += DP[i - 1];
    DP[i] %= MOD;
  }
  while (t--) {
    cin >> a >> b;
    s = DP[b] - DP[a - 1];
    if (s < 0) {
      s += MOD;
    }
    cout << s << endl;
  }
  return 0;
}
