#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int mx = 1e5 + 5;
int dp[mx];
int ans[mx];
signed main() {
  int t, k;
  scanf("%d %d", &t, &k);
  for (int i = 0; i < k; i++) dp[i] = 1;
  for (int i = (int)k; i < (int)mx; i++) {
    dp[i] = dp[i - 1] + dp[i - k];
    if (dp[i] >= mod) dp[i] -= mod;
  }
  ans[0] = 1;
  for (int i = (int)1; i < (int)mx; i++) {
    ans[i] = ans[i - 1] + dp[i];
    if (ans[i] >= mod) ans[i] -= mod;
  }
  while (t--) {
    int a, b;
    scanf("%d %d", &a, &b);
    cout << (ans[b] - ans[a - 1] + mod) % mod << endl;
  }
}
