#include <bits/stdc++.h>
long long int typedef lli;
lli dp[100001], qs[100001];
int main() {
  int t, k;
  scanf("%d%d", &t, &k);
  qs[0] = dp[0] = 1;
  for (int i = 1; i <= 100000; ++i) {
    if (i < k)
      dp[i] = 1;
    else
      dp[i] = (dp[i - 1] + dp[i - k]) % 1000000007;
    qs[i] = (dp[i] + qs[i - 1]) % 1000000007;
  }
  int cur = k - 1;
  while (t--) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%I64d\n", (qs[b] - qs[a - 1] < 0) ? qs[b] - qs[a - 1] + 1000000007
                                              : qs[b] - qs[a - 1]);
  }
  return 0;
}
