t,k=map(int, input().split())
mx=100003
mod=1000000007
dp=[0 for _ in range(mx)]
dp[0]=1
for i in range(1,mx):
dp[i]=dp[i-1]
if i>=k:
dp[i]+=dp[i-k]
dp[i]=dp[i]%mod
for i in range(1,mx):
dp[i]=(dp[i]+dp[i-1])%mod
for i in range(t):
a,b=map(int, input().split())
print((dp[b]-dp[a-1])%mod)
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
void solve(ll k , vector<ll>& dp , vector<ll>& dp2) {
ll ans = 0;
ll a , b;
cin >> a >> b;
// for(ll i = k ; i <= 100000 ; i++) {
// cout << dp2[i] << " ";
// }
// cout << dp2[99613] << " " << dp2[95515] << endl;
// cout << dp2[93494] - dp2[58867] << endl;
ans = (dp2[b] - dp2[a - 1])%mod;
cout << ans%mod << endl;
}
int main() {
ll t , k;
cin >> t >> k;
// t = 1;
vector<ll>dp(100001 , 1) , dp2(100001 , 0);
for(ll i = k ; i <= 100000 ; i++) {
dp[i] = (dp[i - 1] + dp[i - k])%mod;
}
for(ll i = 0 ; i <= 100000 ; i++) {
if(i == 0) {
dp2[i] = dp[i];
}
else {
dp2[i] += (dp[i] + dp2[i - 1]);
}
}
while (t--) {
solve(k , dp , dp2);
}
return 0;
}
1166D - Cute Sequences | 1176A - Divide it |
1527A - And Then There Were K | 1618E - Singers' Tour |
1560B - Who's Opposite | 182B - Vasya's Calendar |
934A - A Compatible Pair | 1618F - Reverse |
1684C - Column Swapping | 57C - Array |
1713D - Tournament Countdown | 33A - What is for dinner |
810A - Straight A | 1433C - Dominant Piranha |
633A - Ebony and Ivory | 1196A - Three Piles of Candies |
299A - Ksusha and Array | 448B - Suffix Structures |
1092B - Teams Forming | 1166C - A Tale of Two Lands |
544B - Sea and Islands | 152B - Steps |
1174D - Ehab and the Expected XOR Problem | 1511A - Review Site |
1316A - Grade Allocation | 838A - Binary Blocks |
1515D - Phoenix and Socks | 1624D - Palindromes Coloring |
1552F - Telepanting | 1692G - 2Sort |