#include <bits/stdc++.h>
using namespace std;
int arr[100005], k;
int calc(int x) {
  if (x - k < 0) return arr[x] = 1;
  if (arr[x] != -1) return arr[x];
  return arr[x] = (calc(x - k) + calc(x - 1)) % 1000000007;
}
int main() {
  ios::sync_with_stdio(false);
  for (int(i) = 0; (i) < (100005); (i)++) {
    arr[i] = -1;
  }
  int t, a, b;
  cin >> t >> k;
  for (int(i) = 0; (i) < (100005); (i)++) {
    calc(i);
  }
  for (int(i) = (1); (i) < (100003); (i)++) {
    arr[i] = (arr[i - 1] + arr[i]) % 1000000007;
  }
  for (int(i) = 0; (i) < (t); (i)++) {
    cin >> a >> b;
    cout << (arr[b] - arr[a - 1] + 1000000007) % 1000000007 << "\n";
  }
  return 0;
}
