#include <bits/stdc++.h>
using namespace std;
long long dp[100100][2];
long long sum[100100];
int test, k;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cin >> test >> k;
  dp[0][0] = 1;
  dp[k][1] = 1;
  for (int i = 1; i < 100100; i++) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % 1000000007;
    if (i >= k) dp[i][1] = (dp[i - k][0] + dp[i - k][1]) % 1000000007;
  }
  sum[0] = 0;
  for (int i = 1; i < 100100; i++)
    sum[i] = (sum[i - 1] + dp[i][0] + dp[i][1]) % 1000000007;
  while (test--) {
    int a, b;
    cin >> a >> b;
    cout << (sum[b] - sum[a - 1] + 1000000007) % 1000000007 << endl;
  }
  return 0;
}
