#include <bits/stdc++.h>
using namespace std;
long long dp[100010], qsum[100010];
int main() {
  int n, k;
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  dp[0] = 1;
  for (int i = 1; i <= 1e5; i++) {
    if (i < k)
      dp[i] = dp[i - 1];
    else
      dp[i] = dp[i - 1] + dp[i - k];
    dp[i] %= 1000000007;
  }
  for (int i = 1; i <= 1e5; i++) {
    qsum[i] = qsum[i - 1] + dp[i];
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    cout << (qsum[b] - qsum[a - 1] + 1000000007) % 1000000007 << '\n';
  }
}
