#include<stdio.h>

int a[] = {1,3,5,6,13,16,23,26,33,35,38,45,51,55,56,61,63,73,83,91,96,100,101,103,110,115,121,135,138,146,156,161,166,168,178,195,206,213,216,233,238,243,255,268,271,276,293,311,335,338,348,355,356,363,370,380,385,411,423,425,426,436,451,453,465,475,503,506,510,511,518,528,530,531,553,555,565,583,588,601,616,618,623,628,646,661,671,675,685,693,696,705,710,723,726,741,751,761,765,770,773,800,805,810,818,825,831,861,863,871,903,905,913,926,930,943,958,973,975,1006,1013,1020,1025,1035,1036,1038,1045,1046,1050,1060,1063,1070,1071,1091,1115,1118,1140,1160,1161,1203,1216,1228,1235,1251,1256,1260,1270,1273,1280,1281,1311,1325,1336,1361,1365,1368,1381,1386,1388,1410,1420,1421,1423,1438,1441,1448,1490,1501,1508,1511,1515,1518,1521,1525,1526,1533,1540,1546,1553,1566,1603,1620,1623,1643,1650,1651,1655,1696,1711,1720,1738,1750,1755,1766,1773,1776,1798,1805,1806,1818,1841,1875,1881,1885,1916,1921,1931,1963,1973,1981,1993,2008,2035,2040,2065,2070,2086,2096,2103,2130,2138,2161,2168,2191,2193,2203,2208,2235,2236,2240,2246,2256,2271,2278,2280,2288,2333,2338,2358,2366,2401,2403,2410,2425,2456,2470,2515,2520,2543,2546,2548,2553,2555,2558,2565,2571,2590,2603,2610,2611,2613,2623,2631,2656,2665,2681,2698,2708,2711,2736,2753,2775,2788,2791,2813,2830,2838,2851,2856,2865,2876,2908,2915,2943,2960,2973,2998,3008,3020,3036,3038,3066,3073,3075,3076,3106,3110,3113,3131,3143,3163,3190,3205,3236,3246,3248,3268,3281,3283,3311,3341,3348,3351,3391,3401,3418,3435,3440,3451,3468,3491,3505,3528,3531,3566,3580,3593,3598,3600,3610,3631,3633,3636,3643,3671,3675,3685,3688,3691,3741,3755,3778,3786,3790,3796,3801,3820,3835,3845,3855,3905,3916,3918,3930,3946,3960,3961,3971,3976,3978,3983,3988,4010,4016,4028,4056,4063,4065,4086,4105,4116,4118,4133,4140,4163,4185,4195,4198,4235,4241,4263,4268,4270,4290,4293,4303,4338,4340,4353,4360,4371,4375,4401,4405,4413,4423,4426,4440,4450,4493,4510,4511,4515,4518,4535,4543,4545,4556,4560,4581,4588,4615,4625,4636,4653,4660,4661,4671,4675,4676,4683,4700,4703,4725,4731,4735,4738,4741,4756,4758,4766,4770,4781,4788,4821,4846,4868,4870,4878,4881,4891,4921,4933,4935,4940,4945,4986,5018,5028,5031,5053,5061,5078,5088,5096,5105,5108,5130,5138,5140,5143,5155,5178,5206,5208,5211,5221,5231,5276,5283,5295,5308,5315,5326,5346,5353,5365,5376,5393,5431,5441,5451,5453,5458,5463,5473,5490,5525,5530,5550,5558,5571,5581,5588,5596,5606,5623,5628,5645,5648,5661,5666,5676,5690,5710,5728,5750,5756,5788,5791,5808,5823,5843,5848,5858,5875,5885,5910,5915,5936,5945,5946,5966,5985,6006,6040,6051,6075,6078,6095,6118,6123,6130,6141,6173,6193,6198,6226,6251,6261,6265,6310,6316,6326,6361,6380,6383,6396,6428,6470,6513,6516,6523,6573,6575,6611,6613,6628,6638,6641,6650,6656,6673,6681,6685,6706,6725,6726,6743,6751,6765,6793,6803,6821,6835,6846,6855,6880,6915,6923,6935,6936,6953,6968,6975,6981,7010,7026,7056,7058,7066,7076,7108,7111,7121,7143,7161,7196,7201,7265,7271,7278,7285,7286,7293,7296,7331,7343,7348,7353,7355,7376,7395,7408,7416,7441,7486,7493,7510,7590,7615,7616,7626,7663,7670,7713,7730,7735,7741,7745,7758,7761,7791,7803,7826,7836,7843,7856,7860,7870,7881,7898,7903,7916,7938,7943,7950,7965,7968,7976,7978,8008,8013,8015,8041,8043,8081,8090,8098,8125,8130,8148,8151,8168,8228,8246,8273,8298,8305,8323,-1};
int cnt[100000];
int j, q, c;
int main() {
    cnt[3] = cnt[4] = 1; cnt[5] = 2;
    for (int i = 6; i < 100000; ++i) cnt[i] = cnt[i - 1] + (i % 12 == 1 && a[j] == i / 12 && ++j);
    while (1) {
        c = getchar_unlocked();
        if ('0' <= c && c <= '9') q = q * 10 + c - '0';
        else break;
    }
    for (int i = 0; i < q; ++i) {
        int l = 0, r = 0;
        while (1) {
            c = getchar_unlocked();
            if ('0' <= c && c <= '9') l = l * 10 + c - '0';
            else break;
        }
        while (1) {
            c = getchar_unlocked();
            if ('0' <= c && c <= '9') r = r * 10 + c - '0';
            else break;
        }
        int ans = cnt[r] - cnt[l - 1];
        if (ans >= 100)
            putchar_unlocked(ans / 100 + '0');
        if (ans >= 10)
            putchar_unlocked(ans / 10 % 10 + '0');
        putchar_unlocked(ans % 10 + '0');
        putchar_unlocked('\n');
    }
}


Measured memory_bytes: 896