#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, k, l, r;
  cin >> n >> k;
  long long a[100000 + 1];
  for (i = 0; i < k; i++) a[i] = 1;
  for (i = k; i <= 100000; i++)
    a[i] = ((a[i - 1] % 1000000007) + (a[i - k] % 1000000007)) % 1000000007;
  for (i = 1; i <= 100000; i++)
    a[i] = ((a[i] % 1000000007) + (a[i - 1] % 1000000007)) % 1000000007;
  while (n-- > 0) {
    cin >> l >> r;
    cout << (a[r] - a[l - 1] + 1000000007) % 1000000007 << endl;
  }
  return 0;
}
