#include <bits/stdc++.h>
using namespace std;
vector<long long> licz;
vector<long long> pre;
int main() {
ios_base::sync_with_stdio(0);
long long n,a,b,c = 1,gdzie;
for(long long i = 1;c <= 10000000000000LL;++i)
{
c *= i;
licz.push_back(c);
gdzie = licz.size()-2;
for(long long j = 0;j <= gdzie;++j)
{
licz.push_back(licz[j]+c);
}
}
cout << licz.size();
pre.push_back(0);
for(long long i = 0;i < licz.size();++i)
{
pre.push_back(pre.back()+licz[i]);
}
cin >> n;
int l,p;
for(int i = 0;i < n;++i)
{
cin >> a >> b;
l = lower_bound(licz.begin(),licz.end(),a)-licz.begin()+1;
p = upper_bound(licz.begin(),licz.end(),b)-licz.begin();
//cout << l << ' ' << p << ' ';
cout << pre[p]-pre[l-1] << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2ZWN0b3I8bG9uZyBsb25nPiBsaWN6Owp2ZWN0b3I8bG9uZyBsb25nPiBwcmU7CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBsb25nIGxvbmcgbixhLGIsYyA9IDEsZ2R6aWU7CiAgICBmb3IobG9uZyBsb25nIGkgPSAxO2MgPD0gIDEwMDAwMDAwMDAwMDAwTEw7KytpKQogICAgewogICAgICAgIGMgKj0gaTsKICAgICAgICBsaWN6LnB1c2hfYmFjayhjKTsKICAgICAgICBnZHppZSA9IGxpY3ouc2l6ZSgpLTI7CiAgICAgICAgZm9yKGxvbmcgbG9uZyBqID0gMDtqIDw9IGdkemllOysraikKICAgICAgICB7CiAgICAgICAgICAgIGxpY3oucHVzaF9iYWNrKGxpY3pbal0rYyk7CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBsaWN6LnNpemUoKTsKICAgIHByZS5wdXNoX2JhY2soMCk7CiAgICBmb3IobG9uZyBsb25nIGkgPSAwO2kgPCBsaWN6LnNpemUoKTsrK2kpCiAgICB7CiAgICAgICAgcHJlLnB1c2hfYmFjayhwcmUuYmFjaygpK2xpY3pbaV0pOwogICAgfQogICAgY2luID4+IG47CiAgICBpbnQgbCxwOwogICAgZm9yKGludCBpID0gMDtpIDwgbjsrK2kpCiAgICB7CiAgICAgICAgY2luID4+IGEgPj4gYjsKICAgICAgICBsID0gbG93ZXJfYm91bmQobGljei5iZWdpbigpLGxpY3ouZW5kKCksYSktbGljei5iZWdpbigpKzE7CiAgICAgICAgcCA9IHVwcGVyX2JvdW5kKGxpY3ouYmVnaW4oKSxsaWN6LmVuZCgpLGIpLWxpY3ouYmVnaW4oKTsKICAgICAgICAvL2NvdXQgPDwgbCA8PCAnICcgPDwgcCA8PCAnICc7CiAgICAgICAgY291dCA8PCBwcmVbcF0tcHJlW2wtMV0gPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9