#include <fstream>
#include <algorithm>

using namespace std;
ifstream fi("sump.inp");
ofstream fo("sump.out");

int e[100001] = {0};
int sang(int n)
{
    e[0] = 1; e[1] = 1;
    for (int i = 2 ; i * i <= n; i++)
        if (e[i] == 0)
           for (int j = i*i; j <= n; j += i) e[j] = 1;
}

int main()
{
    ios::sync_with_stdio(false);
    int t,n,a,b;
    long long m,c[100001];
    sang(100000);
    for (int i = 1; i <= 100000; i++)
    {
        c[i] = m;
        if (e[i] == 0) m += i;
    }
    fi >> t;
    for (int i = 0; i < t; i++)
    {
        fi >> a >> b;
        m = c[b] - c[a];
        fo << m << endl;
    }
    return 0;
}

