#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t, k; if (!(cin >> t >> k)) return 0;
    vector<pair<int, int>> queries(t); int limit = 0;
    for (auto& [a, b] : queries) { cin >> a >> b; limit = max(limit, b); }
    const int mod = 1000000007;
    vector<int> dp(limit + 1), pref(limit + 1); dp[0] = 1;
    for (int i = 1; i <= limit; ++i) {
        dp[i] = dp[i - 1];
        if (i >= k) dp[i] = (dp[i] + dp[i - k]) % mod;
        pref[i] = (pref[i - 1] + dp[i]) % mod;
    }
    for (auto [a, b] : queries)
        cout << (pref[b] - pref[a - 1] + mod) % mod << '\n';
}
