#include <bits/stdc++.h>
using namespace std;
long long int modulo = 1000000007;
int main(int argc, char** argv) {
  int t, k;
  cin >> t >> k;
  vector<long long int> ways(100001, 0);
  ways[0] = 1;
  for (int i = 1; i < ways.size(); ++i) {
    ways[i] += ways[i - 1];
    if (i - k >= 0) {
      ways[i] += ways[i - k];
    }
    ways[i] %= modulo;
  }
  vector<long long int> sum(100001, 0);
  sum[0] = ways[0];
  for (int i = 1; i < sum.size(); ++i) {
    sum[i] = sum[i - 1] + ways[i];
    sum[i] %= modulo;
  }
  for (int i = 0; i < t; ++i) {
    int a, b;
    cin >> a >> b;
    cout << (2 * modulo + sum[b] - sum[a - 1]) % modulo << "\n";
  }
  return 0;
}
