#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const double EPS = 1E-6;
const int INF = 2 * (1e+9) + 1;
const int MAXN = 3 * 100000001;
const int MOD = (1e+9) + 7;
int n, m, t, k;
int dp[100100][2];
int sum[100100];
int main() {
  cin >> t >> k;
  dp[k][1] = dp[1][0] = 1;
  for (int i = (1); i <= (100010); ++i) {
    dp[i][0] = (dp[i - 1][1] + dp[i][0]) % MOD;
    dp[i][0] = (dp[i][0] + dp[i - 1][0]) % MOD;
    if (i - k >= 0 && i > k) {
      dp[i][1] = (dp[i - k][1] + dp[i][1]) % MOD;
      dp[i][1] = (dp[i - k][0] + dp[i][1]) % MOD;
    }
    sum[i] = (((sum[i - 1] + dp[i][0]) % MOD) + dp[i][1]) % MOD;
  }
  while (t--) {
    int a, b;
    cin >> a >> b;
    int ans = (sum[b] - sum[a - 1] + MOD) % MOD;
    cout << ans << endl;
  }
  return 0;
}
