#include <cstdio>
#include <algorithm>
using namespace std;
bool check(int x)
{
    int sum = 0;
    for (int i = 1; i < x; i++)
        if (x % i == 0)
            sum += i;
    return sum == x;
}
int main()
{
    int a, b, n, x;
    scanf("%d", &n);
    while (n--)
    {
        x = 0;
        scanf("%d%d", &a, &b);
        if (a > b) swap(a, b);
        for (int i = a; i <= b; i++)
            if (check(i)) x++;
        printf("%d\n", x);
    }
    return 0;
}