#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, x, y, t;
  cin >> t >> k;
  int dp[100001][2];
  int ans[100001];
  dp[0][0] = 0;
  dp[0][1] = 1;
  for (int i = 1; i <= 100000; i++) {
    if (i < k) {
      dp[i][0] = 0;
      dp[i][1] = 1;
    } else {
      dp[i][0] = dp[i - k][1] + dp[i - k][0];
      dp[i][0] = dp[i][0] % 1000000007;
      dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
      dp[i][1] = dp[i][1] % 1000000007;
    }
    ans[i] = dp[i][1] + dp[i][0];
    ans[i] = ans[i] % 1000000007;
    ans[i] = ans[i] + ans[i - 1];
    ans[i] = ans[i] % 1000000007;
  }
  while (t--) {
    cin >> x >> y;
    int ANS = (ans[y] - ans[x - 1] + 1000000007) % 1000000007;
    cout << ANS << endl;
  }
  return 0;
}
