#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double Tau = 2 * acos(-1);
long long t, k, dp[N], a, b;
int main() {
  cin >> t >> k;
  for (int i = 0; i < k; i++) dp[i] = 1;
  for (int i = k; i < N; i++)
    dp[i] = (1LL * dp[i - 1] + 1LL * dp[i - k]) % 1000000007;
  for (int i = 1; i < N; i++) dp[i] += dp[i - 1] + 1000000007;
  for (int i = 1; i < N; i++) dp[i] %= 1000000007;
  while (t--)
    scanf("%lld%lld", &a, &b),
        printf("%lld\n", (dp[b] - dp[a - 1] + 1000000007) % 1000000007);
}
