#include <bits/stdc++.h>
#define N 10000000
using namespace std;
ifstream f1("CPRIME.inp");
ofstream f2("CPRIME.out");
long long i,j,n,a[10000000],b[10000000],k,dem;
bool check[N + 1];
void main1()
{
  for ( i = 2; i <= N; i++) {
    check[i] = true;
  }
  for ( i = 2; i <= N; i++) {
    if (check[i] == true) {
      for (j = 2 * i; j <= N; j += i) {
        check[j] = false;
      }
    }
  }
}
long long tongnt(long long g,long long h)
{
    dem=0;
    main1();
    for(long long l=g;l<=h;l++){
        if(check[l]==true){
            dem=dem+l;
        }
    }
    return dem;
}
int main()
{
    f1>>n;
    for(i=1;i<=n;i++){
        f1>>a[i]>>b[i];
    }
    for(i=1;i<=n;i++){
        f2<<tongnt(a[i],b[i])<<endl;
    }
}

