#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const long long int INF = 1011111111;
const long long int LLINF = 1000111000111000111LL;
const long double EPS = 1e-10;
const long double PI = 3.14159265358979323;
using namespace std;
long long int power(int x, int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return power((x * x), n / 2);
  else
    return x * power((x * x), (n - 1) / 2);
}
vector<long long int> seve;
void seveprime() {
  int prime[1000000] = {0};
  for (int i = 2; i * i < 1000000; i++) {
    if (prime[i] == 0) {
      for (int j = i * 2; j <= 1000000; j += i) prime[j] = 1;
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (prime[i] == 0) seve.push_back(i);
  }
}
long long int dp[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, i, j, k, t;
  n = 100000;
  cin >> t >> k;
  dp[0] = 0;
  dp[1] = 1;
  for (i = 1; i < k; i++) dp[i] = 1;
  dp[k] = 2;
  for (i = k + 1; i <= n; i++) {
    dp[i] = (dp[i - 1] % MOD + dp[i - k] % MOD) % MOD;
  }
  dp[0] = 0;
  for (i = 1; i <= n; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
  }
  while (t--) {
    cin >> i >> j;
    cout << (dp[j] - dp[i - 1] + MOD) % MOD << '\n';
  }
}
