#include <bits/stdc++.h>
using namespace std;
int k, t, x, y;
long long a[100100], sum[100100];
int main() {
  cin >> t >> k;
  for (int i = 1; i < k; i++) {
    a[i] = 1;
  }
  a[k] = 2;
  for (int i = k + 1; i <= 100000; i++) {
    a[i] = ((a[i - k] % 1000000007) + (a[i - 1] % 1000000007)) % 1000000007;
  }
  sum[0] = 0;
  sum[1] = a[1];
  for (int i = 2; i <= 100000; i++) {
    sum[i] = ((sum[i - 1] % 1000000007) + (a[i] % 1000000007)) % 1000000007;
  }
  for (int i = 1; i <= t; i++) {
    cin >> x >> y;
    cout << (sum[y] - sum[x - 1] + 1000000007) % 1000000007 << '\n';
  }
  return 0;
}
