/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
using namespace std;
int vis[10005];
int t, l, r;
void init(){
for (int i = 2; i <= 10000; i++){
int t = sqrt((double)i);
int sum = 1;
for (int j = 2; j <= t; j++){
if(i % j == 0 && j * j != i){
sum += j + i / j;
}else if(i % j == 0){
sum += j;
}
}
if(sum == i) vis[i] = 1;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
init();
scanf("%d", &t);
while(t--){
scanf("%d %d", &l, &r);
if(l > r) swap(l, r);
int ans = 0;
for (int i = l; i <= r; i++){
if(vis[i]) ans++;
}
printf("%d\n", ans);
}
return 0;
}
/**/
注意num1,num2有可能num1>num2,不然提交是错的