#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
const int N = 1000001;
int dp[N];
int binpow(int base, int exponent){
int result = 1;
if(exponent == 0) return result;
if(exponent == 1) return base;
result = binpow(base, exponent / 2);
result *= result;
result %= mod;
if(exponent % 2) result *= base;
return result % mod;
}
int sol(int n){
return (4 * binpow(5, n - 1)) % mod;
}
signed main(){
int t;
cin >> t;
dp[0] = 0;
dp[1] = 5;
for(int i = 2; i < N; i++) dp[i] = (sol(i) + dp[i - 1]) % mod;
while(t--){
int l, r;
cin >> l >> r;
cout << (dp[r] - dp[l - 1] + mod) % mod << '\n';
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCmNvbnN0IGludCBtb2QgPSAxZTkgKyA3Owpjb25zdCBpbnQgTiA9IDEwMDAwMDE7CmludCBkcFtOXTsKaW50IGJpbnBvdyhpbnQgYmFzZSwgaW50IGV4cG9uZW50KXsKICAgIGludCByZXN1bHQgPSAxOwogICAgaWYoZXhwb25lbnQgPT0gMCkgcmV0dXJuIHJlc3VsdDsKICAgIGlmKGV4cG9uZW50ID09IDEpIHJldHVybiBiYXNlOwogICAgcmVzdWx0ID0gYmlucG93KGJhc2UsIGV4cG9uZW50IC8gMik7CiAgICByZXN1bHQgKj0gcmVzdWx0OwogICAgcmVzdWx0ICU9IG1vZDsKICAgIGlmKGV4cG9uZW50ICUgMikgcmVzdWx0ICo9IGJhc2U7CiAgICByZXR1cm4gcmVzdWx0ICUgbW9kOwp9CmludCBzb2woaW50IG4pewogICAgcmV0dXJuICg0ICogYmlucG93KDUsIG4gLSAxKSkgJSBtb2Q7Cn0Kc2lnbmVkIG1haW4oKXsKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICBkcFswXSA9IDA7CiAgICBkcFsxXSA9IDU7CiAgICBmb3IoaW50IGkgPSAyOyBpIDwgTjsgaSsrKSBkcFtpXSA9IChzb2woaSkgKyBkcFtpIC0gMV0pICUgbW9kOwogICAgd2hpbGUodC0tKXsKICAgICAgICBpbnQgbCwgcjsKICAgICAgICBjaW4gPj4gbCA+PiByOwogICAgICAgIGNvdXQgPDwgKGRwW3JdIC0gZHBbbCAtIDFdICsgbW9kKSAlIG1vZCA8PCAnXG4nOwogICAgfQogICAgcmV0dXJuIDA7Cn0=