#include <bits/stdc++.h>
using namespace std;
const long long MXN = 1e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double EPS = 1e-9;
const long double PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";
long long T, k;
long long dp[MXN], pr[MXN];
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%I64d%I64d", &T, &k);
  dp[0] = 1;
  for (long long i = 1; i <= 1e5 + 1; i++) {
    dp[i] = (dp[i - 1] + dp[i - k]) % MOD;
    pr[i] = pr[i - 1] + dp[i];
  }
  while (T--) {
    long long a, b;
    scanf("%I64d%I64d", &a, &b);
    printf("%I64d\n", (pr[b] - pr[a - 1]) % MOD);
  }
  return 0;
}
