#include<stdio.h>
int p[10001];
void chart()
{
p[0] = 0;
for (int i = 1; i <= 10010; ++i)
{
int f = 1, sum = 0;
for (int k = 1; k <= i / 2; ++k)
{
if (i % k == 0)
sum += k;
if (sum > i)
break;
}
if (i == sum)
p[i] = p[i - 1] + 1;
else
p[i] = p[i - 1];
}
}
int main()
{
chart();
int a, b, t;
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &b, &a);
if (a < b)
a ^= b ^= a ^= b;
printf("%d\n", p[a] - p[b - 1]);
}
return 0;
}