#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define LL long long #define N 210010 #define mod 1000000007 int a[21]={0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6}; int b[10]={0,0,6,6,5,5,5,7,6,6}; int c[1010];//={0,3,6,11,15,19,22,27,32,36,39,45,51,59,67,74,81,90,98,106,112,121,130,141,151,161,170,181,192,202,208,217,226,237,247,257,266,277,288,298,303,311,319,329,338,347,355,365,375,384,389,397,405,415,424,433,441,451,461,470,475,483,491,501,510,519,527,537,547,556,563,573,583,595,606,617,627,639,651,662,668,677,686,697,707,717,726,737,748,758,764,773,782,793,803,813,822,833,844,854,864,880,896,914,931,948,964,982,1000,1017,1033,1052,1071,1092,1113,1133,1153,1175,1196,1217,1236,1258,1280,1304,1327,1350,1372,1396,1420,1443,1466,1488,1510,1534,1557,1580,1602,1626,1650,1673,1695,1716,1737,1760,1782,1804,1825,1848,1871,1893,1915,1936,1957,1980,2002,2024,2045,2068,2091,2113,2135,2156,2177,2200,2222,2244,2265,2288,2311,2333,2357,2380,2403,2428,2452,2476,2499,2524,2549,2573,2596,2618,2640,2664,2687,2710,2732,2756,2780,2803,2826,2848,2870,2894,2917,2940,2962,2986,3010,3033,3043,3059,3075,3093,3110,3127,3143,3161,3179,3196,3212,3231,3250,3271,3292,3312,3332,3354,3375,3396,3415,3437,3459,3483,3506,3529,3551,3575,3599,3622,3645,3667,3689,3713,3736,3759,3781,3805,3829,3852,3874,3895,3916,3939,3961,3983,4004,4027,4050,4072,4094,4115,4136,4159,4181,4203,4224,4247,4270,4292,4314,4335,4356,4379,4401,4423,4444,4467,4490,4512,4536,4559,4582,4607,4631,4655,4678,4703,4728,4752,4775,4797,4819,4843,4866,4889,4911,4935,4959,4982,5005,5027,5049,5073,5096,5119,5141,5165,5189,5212,5224,5242,5260,5280,5299,5318,5336,5356,5376,5395,5413,5434,5455,5478,5501,5523,5545,5569,5592,5615,5636,5660,5684,5710,5735,5760,5784,5810,5836,5861,5886,5910,5934,5960,5985,6010,6034,6060,6086,6111,6135,6158,6181,6206,6230,6254,6277,6302,6327,6351,6375,6398,6421,6446,6470,6494,6517,6542,6567,6591,6615,6638,6661,6686,6710,6734,6757,6782,6807,6831,6857,6882,6907,6934,6960,6986,7011,7038,7065,7091,7116,7140,7164,7190,7215,7240,7264,7290,7316,7341,7366,7390,7414,7440,7465,7490,7514,7540,7566,7591,7602,7619,7636,7655,7673,7691,7708,7727,7746,7764,7781,7801,7821,7843,7865,7886,7907,7930,7952,7974,7994,8017,8040,8065,8089,8113,8136,8161,8186,8210,8234,8257,8280,8305,8329,8353,8376,8401,8426,8450,8473,8495,8517,8541,8564,8587,8609,8633,8657,8680,8703,8725,8747,8771,8794,8817,8839,8863,8887,8910,8933,8955,8977,9001,9024,9047,9069,9093,9117,9140,9165,9189,9213,9239,9264,9289,9313,9339,9365,9390,9414,9437,9460,9485,9509,9533,9556,9581,9606,9630,9654,9677,9700,9725,9749,9773,9796,9821,9846,9870,9881,9898,9915,9934,9952,9970,9987,10006,10025,10043,10060,10080,10100,10122,10144,10165,10186,10209,10231,10253,10273,10296,10319,10344,10368,10392,10415,10440,10465,10489,10513,10536,10559,10584,10608,10632,10655,10680,10705,10729,10752,10774,10796,10820,10843,10866,10888,10912,10936,10959,10982,11004,11026,11050,11073,11096,11118,11142,11166,11189,11212,11234,11256,11280,11303,11326,11348,11372,11396,11419,11444,11468,11492,11518,11543,11568,11592,11618,11644,11669,11693,11716,11739,11764,11788,11812,11835,11860,11885,11909,11933,11956,11979,12004,12028,12052,12075,12100,12125,12149,12159,12175,12191,12209,12226,12243,12259,12277,12295,12312,12328,12347,12366,12387,12408,12428,12448,12470,12491,12512,12531,12553,12575,12599,12622,12645,12667,12691,12715,12738,12761,12783,12805,12829,12852,12875,12897,12921,12945,12968,12990,13011,13032,13055,13077,13099,13120,13143,13166,13188,13210,13231,13252,13275,13297,13319,13340,13363,13386,13408,13430,13451,13472,13495,13517,13539,13560,13583,13606,13628,13652,13675,13698,13723,13747,13771,13794,13819,13844,13868,13891,13913,13935,13959,13982,14005,14027,14051,14075,14098,14121,14143,14165,14189,14212,14235,14257,14281,14305,14328,14340,14358,14376,14396,14415,14434,14452,14472,14492,14511,14529,14550,14571,14594,14617,14639,14661,14685,14708,14731,14752,14776,14800,14826,14851,14876,14900,14926,14952,14977,15002,15026,15050,15076,15101,15126,15150,15176,15202,15227,15251,15274,15297,15322,15346,15370,15393,15418,15443,15467,15491,15514,15537,15562,15586,15610,15633,15658,15683,15707,15731,15754,15777,15802,15826,15850,15873,15898,15923,15947,15973,15998,16023,16050,16076,16102,16127,16154,16181,16207,16232,16256,16280,16306,16331,16356,16380,16406,16432,16457,16482,16506,16530,16556,16581,16606,16630,16656,16682,16707,16719,16737,16755,16775,16794,16813,16831,16851,16871,16890,16908,16929,16950,16973,16996,17018,17040,17064,17087,17110,17131,17155,17179,17205,17230,17255,17279,17305,17331,17356,17381,17405,17429,17455,17480,17505,17529,17555,17581,17606,17630,17653,17676,17701,17725,17749,17772,17797,17822,17846,17870,17893,17916,17941,17965,17989,18012,18037,18062,18086,18110,18133,18156,18181,18205,18229,18252,18277,18302,18326,18352,18377,18402,18429,18455,18481,18506,18533,18560,18586,18611,18635,18659,18685,18710,18735,18759,18785,18811,18836,18861,18885,18909,18935,18960,18985,19009,19035,19061,19086,19097,19114,19131,19150,19168,19186,19203,19222,19241,19259,19276,19296,19316,19338,19360,19381,19402,19425,19447,19469,19489,19512,19535,19560,19584,19608,19631,19656,19681,19705,19729,19752,19775,19800,19824,19848,19871,19896,19921,19945,19968,19990,20012,20036,20059,20082,20104,20128,20152,20175,20198,20220,20242,20266,20289,20312,20334,20358,20382,20405,20428,20450,20472,20496,20519,20542,20564,20588,20612,20635,20660,20684,20708,20734,20759,20784,20808,20834,20860,20885,20909,20932,20955,20980,21004,21028,21051,21076,21101,21125,21149,21172,21195,21220,21244,21268,21291,21316,21341,21365,21376}; int main() { int T,n; cin>>T; while(T--) { int sum=0,ans,ca=1; scanf("%d",&n); //if(n==0) {printf("0\n");continue;} for(int i=1;i<=n;i++){ ans=0; if(i<=20){ ans+=a[i]; } else if(i>20&&i<=100){ if(i==30||i==80||i==90) ans=6; else if(i==40||i==50||i==60) ans=5; else if(i==70) ans=7; else if(i==100) ans=10; else ans=b[i/10]+a[i%10]; } else if(i==1000) ans=11; else{ if(i==200||i==300||i==400||i==500||i==600||i==700||i==800||i==900) ans=a[i/100]+7; else if((i%100)<=20) ans=a[i%100]+10+a[i/100]; else ans=b[(i%100)/10]+a[(i%10)]+10+a[i/100]; } sum+=ans;c[ca++]=sum; } printf("%d\n",sum); //for(int i=1;i<=n;i++) //printf("%d,",c[i]); } return 0; }