#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  int t, k;
  scanf("%d %d", &t, &k);
  int dp[100009];
  for (int i = 0; i <= (int)1e5 + 8; i++) {
    if (i >= k)
      dp[i] = (dp[i - 1] % MOD + dp[i - k] % MOD) % MOD;
    else
      dp[i] = 1 % MOD;
  }
  dp[0] = 0;
  int suma[100000] = {0};
  suma[0] = dp[0];
  for (int i = 1; i <= 100000; i++) {
    suma[i] = ((dp[i]) % MOD + (suma[i - 1]) % MOD) % MOD;
  }
  while (t--) {
    int left, right;
    scanf("%d %d", &left, &right);
    printf("%d\n", (suma[right] - suma[left - 1] + MOD) % MOD);
  }
}
