#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
long long d[100005], s[100005], t, k;
int main() {
  cin >> t >> k;
  for (register int i = 1; i < k; ++i) d[i] = 1;
  d[k] = 2;
  for (register int i = k + 1; i <= 100000; ++i)
    d[i] = (d[i - 1] + d[i - k]) % MOD;
  s[0] = 0;
  s[1] = d[1];
  for (register int i = 2; i <= 100000; ++i) s[i] = s[i - 1] + d[i];
  for (register int i = 1, a, b; i <= t; ++i) {
    cin >> a >> b;
    printf("%lld\n", (s[b] - s[a - 1]) % MOD);
  }
  return 0;
}
