#include <iostream>
using namespace std;
int main() {
int n,a,b,licz=0;
cin>>n;
while(n--){
cin>>a>>b;
for (a;a<=b;a++){
if(a%2==0){
licz++;
}
else if(a%3==0){
licz++;
}
}
cout<<licz;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkKCWludCBuLGEsYixsaWN6PTA7CgljaW4+Pm47CgkKCXdoaWxlKG4tLSl7CgljaW4+PmE+PmI7CgkKCWZvciAoYTthPD1iO2ErKyl7CgkJaWYoYSUyPT0wKXsKCQkJbGljeisrOwoJCX0KCQllbHNlIGlmKGElMz09MCl7CgkJCWxpY3orKzsKCQl9Cgl9Cgljb3V0PDxsaWN6Owp9CglyZXR1cm4gMDsKfQ==