#include <bits/stdc++.h>
using namespace std;
long long dp[int(1e5) + 5], res[int(1e5) + 5];
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  dp[0] = 1;
  for (int i = 1; i <= int(1e5); i++) {
    dp[i] = dp[i - 1];
    if (i >= k) dp[i] = (dp[i] + dp[i - k]) % 1000000007;
    res[i] = (res[i - 1] + dp[i]) % 1000000007;
  }
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", (res[b] - res[a - 1] + 1000000007) % 1000000007);
  }
}
