#include <bits/stdc++.h>
using namespace std;
int k, t;
long long dp[100000 + 10];
long long sum[100000 + 10];
const int MOD = 1000000007;
void makedp() {
  for (int i = 0; i < k; i++) dp[i] = 1;
  for (int i = k; i <= 100005; i++) dp[i] = (dp[i - 1] + dp[i - k]) % MOD;
  sum[0] = dp[0];
  for (int i = 1; i <= 100005; i++) sum[i] = (sum[i - 1] + dp[i]) % MOD;
}
int main() {
  cin >> t >> k;
  makedp();
  int a, b;
  while (t--) {
    scanf("%d%d", &a, &b);
    cout << ((sum[b] - sum[a - 1]) + MOD) % MOD << endl;
  }
  return 0;
}
