#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "pnumbers"

#ifdef LOCAL
static struct __timestamper {
	~__timestamper(){
        TIMESTAMP(end);
	}
} __TIMESTAMPER;
#endif

typedef long long ll;
typedef long double ld;

const ll MAXN = 1.1e18;

vector<ll> res;

void gen0(){
	for (ll i = 1; i <= MAXN; i *= 10){
		res.push_back(i);
		if (i > MAXN/10) break;
	}
}

void genSmall(){
	for (int i = 1; i <= 9; i++)
		res.push_back(i);
}

string vtos(ll val){
	static char buf[20];
	sprintf(buf, LLD, val);
	return buf;
}

ll stov(string val){
	ll res;
	sscanf(val.data(), LLD, &res);
	return res;
}

bool checkPalin(ll x){
	if (x == 0) return 1;
	while (x % 10 == 0) x /= 10;
	string val = vtos(x);
	string rev = val;
	reverse(val.begin(), val.end());
	return val == rev;
}

void check(ll x) {
	if (x > MAXN || x <= 0) return;
	if (checkPalin(x-1) && checkPalin(x+1))
		res.pb(x);
}

void update(ll val){
	int dlt;
	if (val % 10 == 1)
		dlt = 1;
	else if (val % 10 == 9)
		dlt = -1;
	else
		assert(false);
	string sval = vtos(val+dlt);
	string rev = sval; reverse(rev.begin(), rev.end());
	string res;
	res = rev + sval;
	check(stov(res) - dlt);
	res = string(rev.begin(), rev.end()-1) + sval;
	check(stov(res) - dlt); 
	while (rev.size() + sval.size() < 18){
		rev += "0";
		res = rev + sval;
		check(stov(res) - dlt); 
	}
}   

void gen(ll val,int cnt, int c1, int c2,int c3){
	if (cnt == 9) return;
	update(val * 10 + c1);
	gen(val * 10 + c1, cnt + 1, c1, c2, c3);
	gen(val * 10 + c2, cnt + 1, c1, c2, c3);
	gen(val * 10 + c3, cnt + 1, c1, c2, c3);
}

void gen1(){
	gen(0,0,1,2,0);
}

void gen9(){
	gen(0,0,9,8,7);
}


void genAll(){
	res.clear();
	gen0();
	gen1();
	gen9();
	genSmall();
	sort(res.begin(), res.end());
	res.erase(unique(res.begin(),res.end()),res.end());
}


int main(){
    freopen(TASKNAME".in","r",stdin);
    freopen(TASKNAME".out","w",stdout);

    genAll();
    for (int i = 0; i < (int)res.size(); i++)
    	eprintf(LLD"\n", res[i]);
    eprintf("%d\n", res.size());

    int t;
    scanf("%d",&t);
    for (int i = 0; i < t; i++){
    	ll L,R;
    	cin >> L >> R;
    	assert(1 <= L && L <= R && R <= 1000000000000000000LL);
    	cout << upper_bound(res.begin(), res.end(), R) - lower_bound(res.begin(), res.end(), L) << endl;
    }
	    
  return 0;
}