using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] index = new int[] { 1, 2, 6, 18, 30, 36, 78, 96, 138, 156, 198, 210, 228, 270, 306, 330, 336, 366, 378, 438, 498, 546, 576, 600, 606, 618, 660, 690, 726, 810, 828, 876, 936, 966, 996, 1008, 1068, 1170, 1236, 1278, 1296, 1398, 1428, 1458, 1530, 1608, 1626, 1656, 1758, 1866, 2010, 2028, 2088, 2130, 2136, 2178, 2220, 2280, 2310, 2466, 2538, 2550, 2556, 2616, 2706, 2718, 2790, 2850, 3018, 3036, 3060, 3066, 3108, 3168, 3180, 3186, 3318, 3330, 3390, 3498, 3528, 3606, 3696, 3708, 3738, 3768, 3876, 3966, 4026, 4050, 4110, 4158, 4176, 4230, 4260, 4338, 4356, 4446, 4506, 4566, 4590, 4620, 4638, 4800, 4830, 4860, 4908, 4950, 4986, 5166, 5178, 5226, 5418, 5430, 5478, 5556, 5580, 5658, 5748, 5838, 5850, 6036, 6078, 6120, 6150, 6210, 6216, 6228, 6270, 6276, 6300, 6360, 6378, 6420, 6426, 6546, 6690, 6708, 6840, 6960, 6966, 7218, 7296, 7368, 7410, 7506, 7536, 7560, 7620, 7638, 7680, 7686, 7866, 7950, 8016, 8166, 8190, 8208, 8286, 8316, 8328, 8460, 8520, 8526, 8538, 8628, 8646, 8688, 8940, 9006, 9048, 9066, 9090, 9108, 9126, 9150, 9156, 9198, 9240, 9276, 9318, 9396, 9618, 9720, 9738, 9858, 9900, 9906, 9930, 10176, 10266, 10320, 10428, 10500, 10530, 10596, 10638, 10656, 10788, 10830, 10836, 10908, 11046, 11250, 11286, 11310, 11496, 11526, 11586, 11778, 11838, 11886, 11958, 12048, 12210, 12240, 12390, 12420, 12516, 12576, 12618, 12780, 12828, 12966, 13008, 13146, 13158, 13218, 13248, 13410, 13416, 13440, 13476, 13536, 13626, 13668, 13680, 13728, 13998, 14028, 14148, 14196, 14406, 14418, 14460, 14550, 14736, 14820, 15090, 15120, 15258, 15276, 15288, 15318, 15330, 15348, 15390, 15426, 15540, 15618, 15660, 15666, 15678, 15738, 15786, 15936, 15990, 16086, 16188, 16248, 16266, 16416, 16518, 16650, 16728, 16746, 16878, 16980, 17028, 17106, 17136, 17190, 17256, 17448, 17490, 17658, 17760, 17838, 17988, 18048, 18120, 18216, 18228, 18396, 18438, 18450, 18456, 18636, 18660, 18678, 18786, 18858, 18978, 19140, 19230, 19416, 19476, 19488, 19608, 19686, 19698, 19866, 20046, 20088, 20106, 20346, 20406, 20508, 20610, 20640, 20706, 20808, 20946, 21030, 21168, 21186, 21396, 21480, 21558, 21588, 21600, 21660, 21786, 21798, 21816, 21858, 22026, 22050, 22110, 22128, 22146, 22446, 22530, 22668, 22716, 22740, 22776, 22806, 22920, 23010, 23070, 23130, 23430, 23496, 23508, 23580, 23676, 23760, 23766, 23826, 23856, 23868, 23898, 23928, 24060, 24096, 24168, 24336, 24378, 24390, 24516, 24630, 24696, 24708, 24798, 24840, 24978, 25110, 25170, 25188, 25410, 25446, 25578, 25608, 25620, 25740, 25758, 25818, 26028, 26040, 26118, 26160, 26226, 26250, 26406, 26430, 26478, 26538, 26556, 26640, 26700, 26958, 27060, 27066, 27090, 27108, 27210, 27258, 27270, 27336, 27360, 27486, 27528, 27690, 27750, 27816, 27918, 27960, 27966, 28026, 28050, 28056, 28098, 28200, 28218, 28350, 28386, 28410, 28428, 28446, 28536, 28548, 28596, 28620, 28686, 28728, 28926, 29076, 29208, 29220, 29268, 29286, 29346, 29526, 29598, 29610, 29640, 29670, 29916, 30108, 30168, 30186, 30318, 30366, 30468, 30528, 30576, 30630, 30648, 30780, 30828, 30840, 30858, 30930, 31068, 31236, 31248, 31266, 31326, 31386, 31656, 31698, 31770, 31848, 31890, 31956, 32076, 32118, 32190, 32256, 32358, 32586, 32646, 32706, 32718, 32748, 32778, 32838, 32940, 33150, 33180, 33300, 33348, 33426, 33486, 33528, 33576, 33636, 33738, 33768, 33870, 33888, 33966, 33996, 34056, 34140, 34260, 34368, 34500, 34536, 34728, 34746, 34848, 34938, 35058, 35088, 35148, 35250, 35310, 35460, 35490, 35616, 35670, 35676, 35796, 35910, 36036, 36240, 36306, 36450, 36468, 36570, 36708, 36738, 36780, 36846, 37038, 37158, 37188, 37356, 37506, 37566, 37590, 37860, 37896, 37956, 38166, 38280, 38298, 38376, 38568, 38820, 39078, 39096, 39138, 39438, 39450, 39666, 39678, 39768, 39828, 39846, 39900, 39936, 40038, 40086, 40110, 40236, 40350, 40356, 40458, 40506, 40590, 40758, 40818, 40926, 41010, 41076, 41130, 41280, 41490, 41538, 41610, 41616, 41718, 41808, 41850, 41886, 42060, 42156, 42336, 42348, 42396, 42456, 42648, 42666, 42726, 42858, 42966, 43176, 43206, 43590, 43626, 43668, 43710, 43716, 43758, 43776, 43986, 44058, 44088, 44118, 44130, 44256, 44370, 44448, 44496, 44646, 44916, 44958, 45060, 45540, 45690, 45696, 45756, 45978, 46020, 46278, 46380, 46410, 46446, 46470, 46548, 46566, 46746, 46818, 46956, 47016, 47058, 47136, 47160, 47220, 47286, 47388, 47418, 47496, 47628, 47658, 47700, 47790, 47808, 47856, 47868, 48048, 48078, 48090, 48246, 48258, 48486, 48540, 48588, 48750, 48780, 48888, 48906, 49008, 49368, 49476, 49638, 49788, 49830, 49938 };
        int Q = int.Parse(Console.ReadLine());
        int[][] lr = new int[Q][].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        foreach (var a in lr)
        {
            int startindex = (a[0] - 1) / 2;
            int endindex = (a[1] - 1) / 2;
            int count = 0;
            foreach (var i in index)
            {
                if (startindex <= i && i <= endindex) count++;
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 27068