#include <bits/stdc++.h>
using namespace std;
int tc;
long long temp;
long long dp[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, k;
  cin >> t >> k;
  for (int i = 0; i < k; i++) dp[i] = 1;
  for (int i = k; i < 100005; i++) {
    dp[i] = (dp[i - 1] % 1000000007 + dp[i - k] % 1000000007) % 1000000007;
  }
  dp[0] = 0;
  for (int i = 1; i < 100005; i++) {
    dp[i] = dp[i] % 1000000007 + dp[i - 1] % 1000000007;
    dp[i] %= 1000000007;
  }
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (dp[b] >= dp[a - 1])
      cout << (dp[b] - dp[a - 1]) % 1000000007 << '\n';
    else
      cout << (dp[b] - dp[a - 1] + 1000000007) % 1000000007 << '\n';
  }
  return 0;
}
