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