{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the last days. Being inspired by the entrepreneurial spirit of \"HDU CakeMan\", he wants to sell some little things to make money. Of course, this is not an easy task. \n \u003cbr\u003e \n \u003cbr\u003eAs Christmas is around the corner, Boys are busy in choosing christmas presents to send to their girlfriends. It is believed that chain bracelet is a good choice. However, Things are not always so simple, as is known to everyone, girl\u0027s fond of the colorful decoration to make bracelet appears vivid and lively, meanwhile they want to display their mature side as college students. after CC understands the girls demands, he intends to sell the chain bracelet called CharmBracelet. The CharmBracelet is made up with colorful pearls to show girls\u0027 lively, and the most important thing is that it must be connected by a cyclic chain which means the color of pearls are cyclic connected from the left to right. And the cyclic count must be more than one. If you connect the leftmost pearl and the rightmost pearl of such chain, you can make a CharmBracelet. Just like the pictrue below, this CharmBracelet\u0027s cycle is 9 and its cyclic count is 2: \n \u003cbr\u003e \n \u003ccenter\u003e \n \u003cimg style\u003d\"max-width:100%;\" src\u003d\"https://vj.z180.cn/53f6d763e6047bb71352513fe2805f00?v\u003d1611636006\"\u003e \n \u003c/center\u003e \n \u003cbr\u003eNow CC has brought in some ordinary bracelet chains, he wants to buy minimum number of pearls to make CharmBracelets so that he can save more money. but when remaking the bracelet, he can only add color pearls to the left end and right end of the chain, that is to say, adding to the middle is forbidden. \n \u003cbr\u003eCC is satisfied with his ideas and ask you for help. \n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input is a single integer T ( 0 \u0026lt; T \u0026lt;\u003d 100 ) which means the number of test cases. \n\u003cbr\u003eEach test case contains only one line describe the original ordinary chain to be remade. Each character in the string stands for one pearl and there are 26 kinds of pearls being described by \u0027a\u0027 ~\u0027z\u0027 characters. The length of the string Len: ( 3 \u0026lt;\u003d Len \u0026lt;\u003d 100000 )."}},{"title":"Output","value":{"format":"HTML","content":"For each case, you are required to output the minimum count of pearls added to make a CharmBracelet."}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e3\r\naaa\r\nabca\r\nabcde\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e0\r\n2\r\n5\u003c/pre\u003e"}}]}