#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
const int N = 1e5 + 5; 
const int oo = 1e9;

vector <long long> s[100];
vector <int> val;

long long l, r, ans;

bool used[100];
bool cop[100][100];

void backtrack(int i, vector <long long> &a) {
	if (i == (int) val.size()) {
		ans++;
		return;
	}
	backtrack(i + 1, a);
	for (long long x : s[val[i]]) {
		bool ok = true;
		for (long long y : a) if (!cop[x - l][y - l]) {
			ok = false;
			break;
		}
		if (!ok)
			continue;
		a.push_back(x);
		backtrack(i + 1, a);
		a.pop_back();
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> l >> r;
	for (long long i = l; i <= r; i++)
	for (long long j = l; j <= r; j++)
		if (__gcd(i, j) == 1)
			cop[i - l][j - l] = true;

	for (int i = 2; i <= 80; i++) 
	for (long long j = l; j <= r; j++) if (!used[j - l] && j % i == 0) {
		s[i].push_back(j);
		used[j - l] = true;
	}

	for (int i = 2; i <= 80; i++) 
		if (s[i].size()) 
			val.push_back(i);
	
	vector <long long> a;
	backtrack(0, a);
	for (int i = 0; i <= r - l; i++)
		if (!used[i])
			ans <<= 1;
	cout << ans;	
	return 0;
}
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>


using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 320000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 10000;
class shuturyoku_unko {
public:
	char C[MAX * 5];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 4) {
				C[i * 5 + 3 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 5 + 4] = '\n';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 260000;
char dn[dm], * di = dn;
void putint(ll A) {
	int dig = 1;
	if (A >= 100000000) {
		if (A >= 100000000000) dig = 4;
		else if (A >= 10000000000) dig = 3;
		else if (A >= 1000000000) dig = 2;
		memcpy(di + 4 + dig, f.C + A % 10000 * 5, 5);
		A /= 10000;
		memcpy(di + dig, f.C + A % 10000 * 5, 4);
		memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
		di += 9 + dig;
	}
	else {
		if (A >= 10000) {
			if (A >= 10000000) dig = 4;
			else if (A >= 1000000) dig = 3;
			else if (A >= 100000) dig = 2;
			memcpy(di + dig, f.C + A % 10000 * 5, 5);
			memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
			di += 5 + dig;
		}
		else {
			if (A >= 1000) dig = 4;
			else if (A >= 100) dig = 3;
			else if (A >= 10) dig = 2;
			memcpy(di, f.C + A * 5 + 4 - dig, dig + 1);
			di += 1 + dig;
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	fread(cn, 1, 320000, stdin);
	int T = getint();


	rep(t, T) {
		int L = getint(), R = getint();

		ll tmp = R - L - L;
		if (tmp >= 0) putint((tmp + 2) * (tmp + 1) >> 1);
		else putint(0);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}