#include <bits/stdc++.h>
using namespace std;
int n=2;
long long mod=1000000007;
void mult(vector<vector<long long> > &a,vector<vector<long long> > b){
if(a.size()==0){
a=b;
return;
}
vector<vector<long long> > c(n,vector<long long>(n));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
c[i][j]+=a[i][k]*b[k][j];
c[i][j]%=mod;
}
}
}
a=c;
}
void exp(vector<vector<long long> > &a,int m){
if(m<=1)return;
vector<vector<long long> > c;
while(m){
if(m&1){
mult(c,a);
}
mult(a,a);
m>>=1;
}
a=c;
}
long long fib(int x){
if(x==0)return 0;
vector<vector<long long> > a={
{1,1},
{1,0}
};
exp(a,x-1);
return a[0][0]%mod;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int N,M;
cin>>N>>M;
if(N>1)
cout<<(fib(M+2)-fib(N+1)+mod)%mod<<'\n';
else
cout<<(fib(M+2)-1)%mod<<'\n';
}
return 0;
}
Comments
Post a Comment