#include <bits/stdc++.h>
using namespace std;
long long dp[100010];
long long suma[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, k;
  cin >> t;
  cin >> k;
  dp[0] = 1;
  suma[0] = 1;
  long long acu = 0;
  for (int j = 1; j < 100010; j++) {
    long long iz = j - 1 >= 0 ? dp[j - 1] : 0;
    long long der = j - k >= 0 ? dp[j - k] : 0;
    iz = iz % 1000000007;
    der = der % 1000000007;
    dp[j] = (iz + der) % 1000000007;
    acu = (acu + dp[j]) % 1000000007;
    suma[j] = acu;
  }
  for (int i = 0; i < t; i++) {
    int a, b;
    cin >> a;
    cin >> b;
    long long res = suma[b] - suma[a] + dp[a];
    res = res % 1000000007;
    if (res < 0) {
      res = res + 1000000007;
    }
    cout << res << endl;
  }
  return 0;
}
