#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, k, i;
  scanf("%lld %lld", &t, &k);
  long long dp[100001];
  dp[0] = 1;
  for (i = 1; i < 100001; i++) {
    dp[i] = dp[i - 1];
    if (i >= k) dp[i] += dp[i - k];
    dp[i] = dp[i] % 1000000007;
  }
  long long sum[100001];
  sum[0] = dp[0];
  for (i = 1; i < 100001; i++) sum[i] = (dp[i] + sum[i - 1]) % 1000000007;
  while (t--) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    printf("%lld\n", (sum[b] - sum[a - 1] + 1000000007) % 1000000007);
  }
}
