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