We need to understand the problem. Chef has a programming language called Sprout, with three instructions: Load (L), Increment (I), Print (P). The buffer stores an integer 0..25. Load loads any value into buffer (presumably immediate). Increment increments modulo 26: if x<25, x+1; if x=25, 0. Print prints the character corresponding to current buffer value: x -> (x+1)-th letter, i.e., 'a' for 0, 'b' for 1, ..., 'z' for 25.
Constraint: Chef uses load instruction only once at the beginning, before any print. Then he proceeds with instructions (maybe a mix of increment and print). The program must print a given word (string of lowercase letters). We want the shortest possible program (minimum total number of instructions) that prints exactly that word. Then we compare the number of instructions to 11 * (length of word). If instructions <= 11 * length, output "YES", else "NO".
We need to compute the minimum number of instructions needed to print a given string, under these constraints.
Interpretation: We start with a Load instruction that sets buffer to some initial value v0 (0..25). Then we have a sequence of instructions, each either Increment (I) or Print (P). The program prints characters according to the buffer values at each Print. The goal: given target string s of length n, find minimal total instructions = 1 (Load) + number of I + number of P (which is n, because we must print exactly n characters? Actually, Print prints one character; we need to print exactly the word, so we need exactly n Print instructions. So total instructions = 1 (Load) + n (Prints) + (# of increments). We can interleave increments and prints. The buffer changes with increments; increments wrap modulo 26. So essentially, we have a starting value v0 (chosen by the Load), then we have a sequence of n target letters, each with corresponding value t_i in 0..25 (a=0, b=1, ..., z=25). For each print, the current buffer value must equal t_i. Between prints, we can apply some increments (maybe zero). So we need to produce a sequence of operations: start with v0; before first print, we can apply some increments (k1 increments) to change buffer from v0 to v1 = (v0 + k1) mod 26, then Print; then before second print, we apply k2 increments to change from v1 to v2 = (v1 + k2) mod 26 = t_2? Actually, after first print, buffer remains at value t1 (since print doesn't change buffer). Then we apply increments to reach t2, then Print, etc. So the total increments = sum_{i=1}^{n} d_i, where d_i is the number of increments needed to go from t_{i-1} (with t_0 = v0) to t_i, modulo 26. Since increments can be positive only (we cannot decrement directly; we can only increment modulo 26). The minimal number of increments to go from a to b (both in 0..25) is: if a <= b, then b-a; else (26 - (a - b)) = 26 - (a - b) because wrapping around via incrementing through 25 to 0. This is the forward distance modulo 26, i.e., (b - a) mod 26, where we take the non-negative remainder in [0,25]. Indeed, the minimal number of increments = (b - a) mod 26, meaning the smallest non-negative integer k such that (a + k) mod 26 = b. Since we can only increment, that is the minimal k.
Thus, given a starting v0, the total number of increments = sum_{i=1}^{n} ((t_i - t_{i-1}) mod 26), where t_0 = v0.
Total instructions = 1 + n + total_increments.
We are free to choose v0 (0..25) to minimize total_increments.
So we need: For given target string s, compute for each possible start value v0, total_increments(v0) = sum_{i=1}^{n} dist(prev, t_i) where prev starts as v0 then becomes t_i after each print. Then pick min_total_increments = min_{v0 in 0..25} total_increments(v0). Then total_instructions_min = 1 + n + min_total_increments.
Then check if total_instructions_min <= 11 * n.
We need to do this for T test cases, n up to 1000, T up to 100, trivial.
So the main part is computing distances efficiently.
We can precompute t_i values from string: t_i = ord(char) - ord('a').
Then compute cumulative? Actually we can compute total increments for each v0 by iterating i from 1..n, maintaining current value. For each v0 we could compute in O(n) -> 26 * 1000 = 26000 per test case, fine. But we can also compute in O(n) total by noting that total increments for any v0 can be expressed as sum of distances from v0 to first target plus sum of distances between consecutive targets. Actually, note: total increments(v0) = dist(v0, t1) + sum_{i=2}^{n} dist(t_{i-1}, t_i). The second sum is independent of v0. So we can compute base = sum_{i=2}^{n} dist(t_{i-1}, t_i). Then we need to add dist(v0, t1) and maybe also consider? Actually careful: The first term depends on v0: d1 = dist(v0, t1). The rest depend only on consecutive targets. So total_increments(v0) = dist(v0, t1) + sum_{i=2}^{n} dist(t_{i-1}, t_i). So min over v0 of total_increments = min_{v0} dist(v0, t1) + constant. Constant = sum_{i=2}^{n} dist(t_{i-1}, t_i). Since dist(v0, t1) can be any value from 0 to 25 (depending on v0). The minimum possible dist(v0, t1) is 0, achieved by setting v0 = t1. So min_total_increments = 0 + constant = sum_{i=2}^{n} dist(t_{i-1}, t_i). Wait, is that correct? Let's verify: If we set v0 = t1, then no increments before first print, so d1 = 0. Then for i=2, we need dist(t1, t2), etc. So yes, total increments = sum_{i=2}^{n} dist(t_{i-1}, t_i). So min_total_increments is just that sum.
But wait: Is there any constraint that we must use Load only once at beginning? Yes, we can set v0 to any value we want, so we can always set it exactly to the first character's value. So indeed min_total_increments = sum_{i=2}^{n} dist(t_{i-1}, t_i). That seems straightforward.
But there's a nuance: The load instruction must be used only once at the beginning, before any printing. That's allowed. So we can set v0 = t1, so no increments before first print. So indeed the optimal program length is 1 (load) + n (prints) + sum_{i=2}^{n} dist(t_{i-1}, t_i). However, is there any scenario where we might want to use a different v0 to reduce the total number of increments? Possibly if the distances between consecutive letters are large, but we can always set v0 = t1, making first distance 0, so sum of distances from v0 to t1 is at least 0, and the rest are fixed. So minimal sum is indeed sum of consecutive distances. So the optimal program is: load t1, then for each subsequent character, use increments to go from previous printed char to next char, then print. That's optimal.
But wait: Could there be a better strategy where you sometimes don't print immediately after increments? For example, you could do extra increments, then later prints? That would only increase total increments. Or maybe you could interleave prints and increments in a way that you sometimes change buffer after print before next print? That's exactly the model: you print, then you can increment to next target. There's no advantage to not printing when you reach target, since extra increments would just be wasted. So the minimal increments is exactly the sum of minimal forward distances between consecutive characters.
Thus, the total instruction count = 1 + n + S, where S = sum_{i=2}^{n} d_i, with d_i = (t_i - t_{i-1} + 26) mod 26.
Now, the sample input: "helloworld" and "mississippi".
Let's compute for "mississippi". Length = 11? Actually "mississippi" length: m i s s i s s i p p i -> 11 letters? Wait: "mississippi" is 11 letters: m, i, s, s, i, s, s, i, p, p, i -> length 11. But sample output says YES for mississippi, NO for helloworld. Let's compute.
First compute S for "helloworld": h e l l o w o r l d. Let's map to numbers: a=0; h=7, e=4, l=11, l=11, o=14, w=22, o=14, r=17, l=11, d=3.
Compute distances:
Between h(7) and e(4): (4-7) mod 26 = ( -3 mod 26) = 23? Actually minimal increments to go from 7 to 4: increments from 7 -> ... 25 -> 0 -> 4: that's 26-3 = 23. So d1=23.
e(4) to l(11): (11-4)=7.
l(11) to l(11): 0.
l(11) to o(14): 3.
o(14) to w(22): 8.
w(22) to o(14): (14-22) mod26 = ( -8 mod26) = 18.
o(14) to r(17): 3.
r(17) to l(11): (11-17) mod26 = ( -6 mod26) = 20.
l(11) to d(3): (3-11) mod26 = ( -8 mod26)=18.
Sum S = 23+7+0+3+8+18+3+20+18 = Let's sum: 23+7=30, +0=30, +3=33, +8=41, +18=59, +3=62, +20=82, +18=100. So S=100. n=10 (helloworld length 10?). Wait "helloworld" is 10 letters? h e l l o w o r l d -> 10. Actually "helloworld" is 10 characters, but sample says something else? Let's count: h(1) e(2) l(3) l(4) o(5) w(6) o(7) r(8) l(9) d(10) -> yes length 10. So total instructions = 1 + 10 + 100 = 111. Compare to 11*n = 110. Since 111 > 110, so "NO". That matches sample output: NO for helloworld.
Now for "mississippi": length? Let's list: m i s s i s s i p p i. That's 11 letters. But check spelling: m(1) i(2) s(3) s(4) i(5) s(6) s(7) i(8) p(9) p(10) i(11) -> length 11. So 11 * 11 = 121. Need total instructions <= 121 to output YES. Compute S:
Convert to numbers: m=12, i=8, s=18, s=18, i=8, s=18, s=18, i=8, p=15, p=15, i=8.
Now compute distances:
1: m(12) to i(8): (8-12) mod26 = ( -4 mod26) = 22.
2: i(8) to s(18): (18-8)=10.
3: s(18) to s(18): 0.
4: s(18) to i(8): (8-18) mod26 = ( -10 mod26)=16.
5: i(8) to s(18): 10.
6: s(18) to s(18): 0.
7: s(18) to i(8): 16 (since 8-18 = -10 mod26=16) Actually careful: we have: after s(18) to i(8) at step? Let's index properly:
Let t1=12 (m)
t2=8 (i)
t3=18 (s)
t4=18 (s)
t5=8 (i)
t6=18 (s)
t7=18 (s)
t8=8 (i)
t9=15 (p)
t10=15 (p)
t11=8 (i)
So distances:
d2: t1->t2: (8-12) mod26 = 22.
d3: t2->t3: (18-8)=10.
d4: t3->t4: (18-18)=0.
d5: t4->t5: (8-18)= -10 mod26 = 16.
d6: t5->t6: (18-8)=10.
d7: t6->t7: (18-18)=0.
d8: t7->t8: (8-18)=16.
d9: t8->t9: (15-8)=7.
d10: t9->t10: (15-15)=0.
d11: t10->t11: (8-15)= -7 mod26 = 19.
Wait careful: we have 10 distances because n=11, so there are 10 distances (from i=2 to 11). So we have d2,..., d11? Actually we sum over i=2 to n inclusive: sum_{i=2}^{11} dist(t_{i-1}, t_i). So that's 10 distances.
Our computed: d2=22, d3=10, d4=0, d5=16, d6=10, d7=0, d8=16, d9=7, d10=0, d11=19? Wait we have up to i=11, yes d for i=11 is dist(t10, t11) = dist(p=15, i=8) = 19. So that's 10 numbers: 22,10,0,16,10,0,16,7,0,19. Sum them: 22+10=32, +0=32, +16=48, +10=58, +0=58, +16=74, +7=81, +0=81, +19=100. Sum = 100? Actually 81+19=100. So S=100.
But wait earlier we got S=100 for helloworld as well (also 100). So for mississippi, n=11, S=100, total instructions = 1 + 11 + 100 = 112. Compare to 11*n = 121. 112 <= 121, so YES. That matches sample output: YES for mississippi.
Thus the logic is correct.
Hence the problem reduces to: Given a string s, compute total steps = 1 + n + sum_{i=1}^{n-1} dist(s_i, s_{i+1}), where dist(a,b) = (b - a) mod 26 (i.e., (b - a + 26) % 26). Then compare <= 11*n.
But wait, we need to ensure we interpret correctly: The load instruction is counted as one instruction. So total = 1 (load) + number of prints (n) + number of increments (S). So yes.
Now we need to output YES if total <= 11*n, else NO.
We must also ensure we consider the possibility that the word length is 1. Then there are no distances, S=0. Total instructions = 1 + 1 + 0 = 2. Compare to 11*1 = 11, so 2 <= 11 -> YES.
Now confirm that the sum of distances is indeed minimal. Could there be a scenario where we might not set v0 to t1 to reduce total increments? For example, suppose the string is "aba". t1=0 (a), t2=1 (b), t3=0 (a). Distances: t1->t2: 1, t2->t3: (0-1) mod26 = 25. Sum = 26. Total = 1+3+26=30. 11*3=33 => YES? Actually 30 <= 33. But could we do better by setting v0 not to a? Suppose v0=1 (b). Then increments: dist(v0, t1=0) = (0-1) mod26=25. Then t1->t2: dist(0,1)=1, t2->t3: dist(1,0)=25 => total increments = 25+1+25=51, worse. So not better.
What about using more than one load? The problem says "To keep his programs clear, he uses the load instruction only once in the beginning (before printing any character)." So we are constrained to use load only once. However, the problem asks: "Assuming he will write the shortest code (i.e. use the fewest instructions) to print it, will the program be simple?" So we are to find the shortest possible program under that constraint (load only once). That matches our model.
But could there be a program that uses fewer instructions by not following the pattern of printing each character as soon as ready? For instance, could we combine increments in some clever way to reduce total? No, because after each print the buffer remains at that character's value. To print next character, you must get buffer to that next character's value via increments. You could perhaps do multiple prints without increments if the same character appears consecutively, but that's already accounted for by zero distance. There's no way to reduce the sum of distances because each transition must be achieved by at least the minimal number of increments. So it's optimal.
Thus answer: compute sum of mod distances between consecutive letters, add 1 + len(s). Compare to 11*len(s).
We must be careful: The length of word can be up to 1000, T up to 100, so trivial.
Edge Cases: Empty string? Not possible because length >= 1 per constraints.
Implementation: Read T, for each test case read string s. Compute n = len(s). Convert each char to number 0-25. Initialize total_increments = 0. For i from 0 to n-2: a = ord(s[i]) - ord('a'), b = ord(s[i+1]) - ord('a'), dist = (b - a) % 26 (in Python, (b - a) % 26 gives non-negative remainder). Add to total_increments. Then total_instructions = 1 + n + total_increments. If total_instructions <= 11 * n, print "YES", else "NO".
Double-check sample: For helloworld: n=10, total_increments = we computed 100? Actually we computed 100, but earlier we got S=100? Wait we computed S = 100 for helloworld? Let's recalc: helloworld: h(7) e(4) -> dist = (4-7)%26 = (-3)%26 = 23. e(4) l(11) -> (11-4)=7. l(11) l(11) -> 0. l(11) o(14) -> 3. o(14) w(22) -> 8. w(22) o(14) -> (14-22)%26 = (-8)%26=18. o(14) r(17) -> 3. r(17) l(11) -> (11-17)%26 = (-6)%26=20. l(11) d(3) -> (3-11)%26 = (-8)%26=18. Sum: 23+7=30, +0=30, +3=33, +8=41, +18=59, +3=62, +20=82, +18=100. Yes 100. n=10. total_instructions=1+10+100=111. 1110=110. So 111 > 110 => NO. For mississippi: n=11, total_increments=100 (we computed) => total=112, 1111=121 => 112 <=121 => YES. Good.
Thus solution is straightforward.
But wait, sample input "2" then two lines; outputs NO then YES. That matches.
Thus answer: implement as above.
But let me consider potential nuance: The problem says "A program is simple, if the number of instructions is not more than ELEVEN times the length of the word that it prints." So we compare total instructions to 11 * len(word). If total_instructions <= 11 * len(word), then simple? Actually "simple" if number of instructions is not more than eleven times the length. The question: "will the program be simple?" Output "YES" if simple, else "NO". So YES if total_instructions <= 11*n.
But note: In sample, for helloworld, total_instructions = 111 > 110 -> not simple -> NO. For mississippi, total=112 <=121 -> simple -> YES. So matches.
Thus solution is trivial.
Now, could there be any alternative strategies that yield even shorter program? Could we possibly use the load instruction to load a value that is not exactly the first character, but then later we might skip some increments by printing at different times? But each character must be printed in order. The buffer is only modified by increments (and load only at start). After printing a character, we have to do increments to reach the next. The minimal increments for a transition is the forward distance mod 26. There's no way to "save" increments by temporarily going past and then later using decrements? There is no decrement; only increment that wraps. So you can only increase. If you overshoot, you'd have to go all the way around to get back, which would be longer. So minimal is to take the shortest forward path.
Could we possibly load a value that leads to a different path that overall reduces sum of distances? That's essentially choosing v0. The sum is dist(v0, t1) + sum_{i=2}^{n} dist(t_{i-1}, t_i). The first term is minimized (0) by setting v0 = t1. So the best is that.
Thus the problem is solved.
Now let's ensure that the program length is counted correctly: The load instruction is one. Print instructions each count as one. Increment instructions each count as one. So total = 1 + n + increments.
Thus solution.
But I suspect there might be some tricky nuance: The buffer range is 0-25, and increment at 25 goes to 0. That's what we used. Good.
Therefore, we can implement.
But wait: The problem statement says: "Load Instruction can be used to load any value between 0 and 25 (inclusive) into the buffer." It doesn't say that you must load a constant; you can load a specific value. So yes.
Also: "To keep his programs clear, he uses the load instruction only once in the beginning (before printing any character)." So this constraint is part of the definition of a program in this context? Actually it says: "To keep his programs clear, he uses the load instruction only once in the beginning (before printing any character)." This might be describing Chef's typical practice, not a hard constraint? But then later: "A program is simple, if the number of instructions is not more than ELEVEN times the length of the word that it prints." And the problem asks: "Given the word Chef wants his program to print and assuming he will write the shortest code (i.e. use the fewest instructions) to print it, will the program be simple?" So we are to assume Chef writes the shortest code that prints the word, and he also follows his typical practice of using load only once at the beginning. So yes, it's a constraint on the program: load only once at start. That's exactly our model.
But what if the shortest program under that constraint might not be unique? But we just need the minimal number of instructions, which we computed.
Now, could there be a program that uses zero increments? For a string of all same character, e.g., "aaaa", then t1='a', t2='a', etc., distances zero. So total = 1 + n. Compare to 11*n: 1+n <= 11n -> 1 <= 10n, which is true for n>=1. So YES. Good.
Now, maximum possible increments for a string of length n? The maximum distance between consecutive letters is 25 (e.g., from 'a' to 'z'? Actually dist('a', 'z'): a=0, z=25, (25-0)=25; or from 'z' to 'a' is also 25 because (0-25) mod26 = 1? Wait (0-25) mod26 = 1? Actually 0-25 = -25 mod26 = 1? No, -25 mod 26 = 1? Check: ( -25 ) % 26 in Python is 1 because -25 + 26 = 1. But is that the minimal increments? Let's think: from 25 (z) to 0 (a) by increment: 25->0 via one increment? Because at x=25, increment makes it 0. So indeed from z to a, it takes 1 increment, not 25. So the maximum minimal increments between two distinct characters is 25? Actually we need the maximum of (b - a) mod 26 over a,b in [0,25], a≠b. The values range 1..25. So max is 25, when (b-a) mod26 = 25, which happens when a = b+1? For instance, a=1, b=0: (0-1) mod26 = 25. So distance 25 occurs when moving from a letter to the immediately preceding letter in alphabet (e.g., from b to a). Because to go from b (1) to a (0), you need to go from 1 to 25? Wait, check: Starting at 1, increment: 1->2,3,...,25->0, that's 25 increments? Actually from 1 to 0: To reach 0, you need to wrap around: increments: 1->2 (1), 2->3 (2), ... up to 25 (24 increments? Let's count: Starting at 1, after k increments, value = (1+k) mod 26. We want (1+k) mod 26 = 0 => 1+k ≡ 0 mod 26 => k ≡ 25 mod 26 => smallest positive k=25. So yes, 25 increments. So the maximum distance is 25. So total increments for a string of length n could be at most 25*(n-1) (if each transition is maximum). Then total instructions = 1 + n + 25*(n-1) = 1 + n + 25n -25 = 26n -24. Compare to 11n: 26n-24 <= 11n => 15n <= 24 => n <= 1.6, so for n>=2, it's generally > 11n. So many words will be "not simple". But specific words may be simple if transitions are small.
Now, given that the problem is straightforward, the sample and explanation confirm.
Thus we can code.
But hold on: Is there any scenario where Chef could use the load instruction after some prints? The problem says "To keep his programs clear, he uses the load instruction only once in the beginning (before printing any character)." That phrasing might indicate it's a self-imposed rule for clarity, but is it required for the shortest code? Could a program with multiple loads be shorter? Possibly? Because if you could load multiple times, you could set the buffer to the exact value before each print, eliminating the need for increments between prints. Then the program would be: For each character, load its value and then print. But load is one instruction, print is one, so per character that would be 2 instructions, total = 2n. But also perhaps need a load at the beginning? Actually you could do: load t1, print; load t2, print; ... but you must have load before first print. That would be n loads and n prints, total = 2n. That might be less than 1+n+increments if increments are large. But the problem says "he uses the load instruction only once in the beginning". This is presented as a given constraint: Chef will only write programs that use load once at the beginning. So the shortest program under that constraint is what we computed. The problem statement: "To keep his programs clear, he uses the load instruction only once in the beginning (before printing any character)." This is part of Chef's demonstration. So we assume Chef's programs follow that rule. Therefore we cannot use multiple loads.
But just to double-check: The problem asks: "Assuming he will write the shortest code (i.e. use the fewest instructions) to print it, will the program be simple?" The shortest code among all possible Sprout programs? Or among those that follow his rule? It says "To keep his programs clear, he uses the load instruction only once in the beginning." That seems to describe his practice. So we should consider programs that use load only once. It's not explicitly a constraint, but it's a statement about how he writes programs. In such problems, we typically incorporate this as a constraint. Also the sample matches our interpretation. So it's correct.
Now, implementation: We need to read T and then T lines, each containing a word. Possibly there are blank lines? Unlikely.
Edge Cases: Word can have uppercase? It says lowercase English character. So all lowercase.
Now, we produce "YES" or "NO" in uppercase.
Complexity: O(T * n). n max 1000, T max 100 => 100k operations, trivial.
Now, we should also be aware that the modulo operation in some languages might give negative results if not careful. Use ((b - a) + 26) % 26 or (b - a) % 26 in Python works fine because % yields non-negative. In C/C++, use (b - a + 26) % 26 after adjusting for negative.
Now, write code.
But wait, is there any possibility to reduce increments by using the fact that after a print, you could delay printing and perform some increments that help later prints? For example, you could, after printing a character, do some extra increments beyond the next target, then later print a different character, and then later come back? But you must print the characters in order. Suppose we have sequence a, b, c. Could we go from a to some value d, then print something else? No, because the next character to print is b, so you must print b exactly when buffer is b. If you overshoot, you cannot print b because buffer would not be b. So you must exactly match b at the print moment. So any extra increments before printing b would be wasted (unless they are part of the minimal path to b, but if you overshoot you'd have to go around, making it longer). So minimal is direct.
Thus we are done.
Thus answer.
Now, given the problem's apparent simplicity, there might be a trick: The buffer's initial value after load? Could we choose not to load and rely on the initial buffer value? The problem says "Load Instruction: Load a value into buffer." It doesn't specify the initial state of the buffer. Usually there is an initial value, maybe 0? But since we must load once at the beginning, we can set it to whatever we want. So it's fine.
One more nuance: The buffer stores a single integer between 0 and 25 inclusive. At x=25, increment makes 0. So the mod 26 behavior.
Now, the problem: "The Load Instruction can be used to load any value between 0 and 25 (inclusive) into the buffer." So yes.
Thus we are done.
I'll produce final solution explanation and code.
But before finalizing, let's test with a few cases.
Case: "ab": n=2. dist(a->b): (1-0)=1. total = 1+2+1=4. 11*2=22 -> YES.
Case: "ba": a=1,0? Actually b=1, a=0. dist = (0-1) mod26 = 25. total = 1+2+25=28. 22? Actually 11*2=22, 28>22 -> NO.
Case: "zz": n=2, t1=25, t2=25, dist=0, total=1+2+0=3 <=22 -> YES.
Case: "az": dist = (25-0)=25, total=1+2+25=28 >22 -> NO.
Case: "za": dist = (0-25) mod26 = 1, total=1+2+1=4 <=22 -> YES.
So interesting: "za" is simple, "az" is not.
Now, confirm with our formula: If we sum distances for entire string, it's independent of first character because we set v0 to t1. So total = 1 + n + sum_{i=2}^{n} dist(t_{i-1}, t_i). This sum is the total "cost". So for "za", t1=25, t2=0, dist = 1, total=4, YES. For "az", total=1+2+25=28, NO.
Ok.
Now, is there any scenario where we could set v0 not to t1 to reduce total? We already argued no because it would add dist(v0,t1). But could it possibly reduce some later distances? No, because later distances depend only on the actual printed values, not on v0. So it's independent. So min is with v0=t1.
Thus solution is solid.
But wait: What about the possibility of not printing the first character immediately? Could we load a value, then do some increments, then print first character, maybe do extra increments that later reduce total sum? No, because after we print the first character, we are at that character value. The transitions between characters are fixed. The only thing we can control before first print is the initial value and number of increments before first print. But we can also decide to insert extra increments between prints, but that would only increase total. So the minimal is to print immediately after setting buffer to t1.
Thus done.
Now, check constraints: T up to 100, length up to 1000, so at most 100*1000 = 100,000 characters, fine.
Now, we should output YES/NO.
I'll produce solution.
But perhaps we should read input carefully: "Each test case contains 1 word on a line by itself - the word that would be printed by Chef's program." So after T, there are T lines, each contains a word. There might be spaces? No, word.
Now, code: In Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
T = int(data[0])
out = []
idx = 1
for _ in range(T):
s = data[idx]
idx += 1
n = len(s)
increments = 0
prev = ord(s[0]) - 97
for ch in s[1:]:
cur = ord(ch) - 97
increments += (cur - prev) % 26
prev = cur
total = 1 + n + increments
if total <= 11 * n:
out.append("YES")
else:
out.append("NO")
sys.stdout.write("\n".join(out))
That's it.
But let's test with sample:
Input:
2
helloworld
mississippi
Compute: For helloworld, n=10, increments=100, total=111, 11*10=110 -> NO.
For mississippi, n=11, increments=100, total=112, 121 -> YES.
Outputs NO then YES? Sample output: NO YES? Actually sample output is:
NO
YES
So order matches.
All good.
Now, I'll produce final answer. We need to compute the minimum number of instructions required to print the given word under the given constraints. The program must start with a single Load instruction (which sets the buffer to a chosen value between 0 and 25), followed by a sequence of Increment and Print instructions. Each Print outputs the character corresponding to the current buffer value (0 → 'a', 1 → 'b', …, 25 → 'z'). The Increment instruction increases the buffer by 1 modulo 26 (25 → 0). The goal is to minimize the total number of instructions.
Let the word be ( s = c_1 c_2 \ldots c_n ) and define numeric values ( t_i = \text{ord}(c_i) - \text{ord}('a') ). After loading an initial value ( v_0 ), the program must print ( c_1 ) when the buffer equals ( t_1 ). This may require some number of increments ( d_1 = (t_1 - v_0) \bmod 26 ). After printing ( c_1 ), the buffer value is ( t_1 ). To print the next character ( c_2 ), we need ( d_2 = (t_2 - t_1) \bmod 26 ) increments, and so on. Hence the total number of increments is
[
d_{\text{total}} = (t_1 - v_0) \bmod 26 ;+; \sum_{i=2}^{n} (t_i - t_{i-1}) \bmod 26.
]
The total number of instructions is ( 1 ) (Load) ( + n ) (Prints) ( + d_{\text{total}} ). We are free to choose ( v_0 ) to minimize this total. Clearly the minimum is achieved by setting ( v_0 = t_1 ), making the first term zero. Therefore the minimal total instructions are
[
\text{total}{\min} = 1 + n + \sum{i=2}^{n} \bigl( (t_i - t_{i-1}) \bmod 26 \bigr).
]
The program is considered simple if its number of instructions is not more than ( 11 \times n ). Hence we output YES if ( \text{total}_{\min} \le 11n ), otherwise NO.
The computation for each test case is straightforward: iterate over the string, accumulate the forward distances modulo 26 between consecutive letters, add ( 1 + n ), and compare to ( 11n ). The constraints (T ≤ 100, length ≤ 1000) make this very efficient.