#include <fstream>
#include <iostream>
#include <math.h>

#define MAX_SIGNIFICAL 8388608

using namespace std;

int main()
{
	fstream fin;

	fin.open("FLOAT.IN");

	int testCount;
	fin >> testCount;

	for(int i = 0; i < testCount; i++)
	{
		int left, right;
		int result = 0;

		fin >> left >> right;

		if(left < MAX_SIGNIFICAL)
		{
			if(right >= 1000000000)
			{
				result += (right - 1000000000) / 1000;
				result += 1000000000 - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - MAX_SIGNIFICAL;
			}
			else if(right >= MAX_SIGNIFICAL * 100)
			{
				result += right - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - MAX_SIGNIFICAL;
			}
			else if(right >= 100000000)
			{
				result += (right - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - MAX_SIGNIFICAL;
			}
			else if(right >= MAX_SIGNIFICAL * 10)
			{
				result += right - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - MAX_SIGNIFICAL;
			}
			else if(right >= 10000000)
			{
				result += (right - 10000000) / 10;
				result += 10000000 - MAX_SIGNIFICAL;
			}
			else if(right >= MAX_SIGNIFICAL)
			{
				result += right - MAX_SIGNIFICAL;
			}
		}
		else if(left < 10000000)
		{
			if(right >= 1000000000)
			{
				result += (right - 1000000000) / 1000;
				result += 1000000000 - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - left;
			}
			else if(right >= MAX_SIGNIFICAL * 100)
			{
				result += right - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - left;
			}
			else if(right >= 100000000)
			{
				result += (right - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - left;
			}
			else if(right >= MAX_SIGNIFICAL * 10)
			{
				result += right - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - 10000000) / 10;
				result += 10000000 - left;
			}
			else if(right >= 10000000)
			{
				result += (right - 10000000) / 10;
				result += 10000000 - left;
			}
			else if(right >= MAX_SIGNIFICAL)
			{
				result += right - left + 1;
			}
		}
		else if(left < MAX_SIGNIFICAL * 10)
		{
			if(right >= 1000000000)
			{
				result += (right - 1000000000) / 1000;
				result += 1000000000 - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - left) / 10;
			}
			else if(right >= MAX_SIGNIFICAL * 100)
			{
				result += right - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - left) / 10;
			}
			else if(right >= 100000000)
			{
				result += (right - 100000000) / 100;
				result += 100000000 - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - left) / 10;
			}
			else if(right >= MAX_SIGNIFICAL * 10)
			{
				result += right - MAX_SIGNIFICAL * 10;
				result += (MAX_SIGNIFICAL * 10 - left) / 10;
			}
			else if(right >= 10000000)
			{
				result += (right - 100000000) / 10 - (left - 100000000) / 10;
			}
		}
		else if(left < 100000000)
		{
			if(right >= 1000000000)
			{
				result += (right - 1000000000) / 1000;
				result += 1000000000 - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - left;
			}
			else if(right >= MAX_SIGNIFICAL * 100)
			{
				result += right - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - 100000000) / 100;
				result += 100000000 - left;
			}
			else if(right >= 100000000)
			{
				result += (right - 100000000) / 100;
				result += 100000000 - left;
			}
			else if(right >= MAX_SIGNIFICAL * 10)
			{
				result += right - left + 1;
			}
		}
		else if(left < MAX_SIGNIFICAL * 100)
		{
			if(right >= 1000000000)
			{
				result += (right - 1000000000) / 1000;
				result += 1000000000 - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - left) / 100;
			}
			else if(right >= MAX_SIGNIFICAL * 100)
			{
				result += right - MAX_SIGNIFICAL * 100;
				result += (MAX_SIGNIFICAL * 100 - left) / 100;
			}
			else if(right >= 100000000)
			{
				result += (right - 100000000) / 100 - (left - 100000000) / 100;
			}
		}
		else if(left < 1000000000)
		{
			if(right >= 1000000000)
			{
				result += (right - 1000000000) / 1000;
				result += 1000000000 - left;
			}
			else if(right >= MAX_SIGNIFICAL * 100)
			{
				result += right - left + 1;
			}
		}
		else
		{
			if(right >= 1000000000)
			{
				result += (right - 100000000) / 1000 - (left - 100000000) / 1000;
			}
		}

		cout << right - left - result + 1<< endl;
	}

	fin.close();

	return 0;
}