#include<iostream>
using namespace std;
int main(void)
{
bool wanshu(int);
int groups, m, n, i, geshu;
cin >> groups;
while (groups--)
{
geshu = 0;
cin >> m >> n;
int t;
if (m > n)
{
t = m; m = n; n = t;
}
for (i = m; i <= n; i++)
{
if (wanshu(i)) geshu++;
}
cout << geshu << endl;
}
return 0;
}
bool wanshu(int a)
{
bool is = false;
int sum = 0, i;
for (i = 1; i <= a / 2; i++)
{
if (a % i == 0) sum += i;
}
if (sum == a) is = true;
return is;
}
using namespace std;
int main(void)
{
bool wanshu(int);
int groups, m, n, i, geshu;
cin >> groups;
while (groups--)
{
geshu = 0;
cin >> m >> n;
int t;
if (m > n)
{
t = m; m = n; n = t;
}
for (i = m; i <= n; i++)
{
if (wanshu(i)) geshu++;
}
cout << geshu << endl;
}
return 0;
}
bool wanshu(int a)
{
bool is = false;
int sum = 0, i;
for (i = 1; i <= a / 2; i++)
{
if (a % i == 0) sum += i;
}
if (sum == a) is = true;
return is;
}