#include <bits/stdc++.h>
using namespace std;
int dp[100005], sum[100005];
int main() {
  int n, k, a, b;
  cin >> n >> k;
  dp[0] = 1, sum[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    dp[i] = (i >= k ? dp[i - 1] + dp[i - k] : dp[i - 1]) % 1000000007;
  }
  for (int i = 1; i <= 100000; i++) {
    sum[i] = (sum[i - 1] + dp[i]) % 1000000007;
  }
  while (n--) {
    cin >> a >> b;
    cout << (sum[b] - sum[a - 1] + 1000000007) % 1000000007 << endl;
  }
}
