#include <iostream>
using namespace std;
int main() {
long long 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<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkKCWxvbmcgbG9uZyBpbnQgbixhLGIsbGljej0wOwoJY2luPj5uOwoJCgl3aGlsZShuLS0pewoJY2luPj5hPj5iOwoJCglmb3IgKGE7YTw9YjthKyspewoJCWlmKGElMj09MCl7CgkJCWxpY3orKzsKCQl9CgkJZWxzZSBpZihhJTM9PTApewoJCQlsaWN6Kys7CgkJfQoJfQoJY291dDw8bGljejw8ZW5kbDsKfQoJcmV0dXJuIDA7Cn0=