We are given T test cases. Each test case: integer N, then N integers (the chocolates count for each kid). We need to find the maximum length of a contiguous subsequence (i.e., subarray) that satisfies the condition: for every i in the subarray (starting from some index l to r), the value at position i (1-indexed within subarray) should equal sum of previous two values? Let's parse problem statement carefully.
It says: "Watson told the lads to arrange themselves in such a way that, number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid. Now they have arranged themselves in an order. Now Sherlock announced that he will select the students who have formed the line according to this order. But since there can be many such small groups among the entire N kids, he will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition"
Interpretation: We need to find the longest contiguous subarray (or maybe subsequence? Usually such problems ask for contiguous) where each element (starting from the third position of that subarray) equals the sum of the two preceding elements. That's a Fibonacci-like condition.
They guarantee Holmes will select at least 1 or 2 students. But answer may be 1 or 2? However constraints say at least 1 or 2. But the output example: first test case gives 3, second gives 3. For array [2,3,5,1,2], subarray [2,3,5] works because 5=2+3. So length=3. For [1,2,3], check: 3=1+2, so works, length=3. So if whole array works, answer=N, but they didn't have such test.
Edge cases: For N=1, answer should be 1? The condition is trivially satisfied for length 1? But they say Holmes will select at least 1 or 2, so maybe they consider length >= 2? Actually condition requires two previous kids, so length >=3 to satisfy the sum condition. However, the problem says "he will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition." The condition: "number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid." For i >= 3. For i=1 and i=2, the condition does not apply because there are no (i-1) and (i-2) both exist? The statement might imply that for the entire sequence they arrange themselves so that each kid's chocolates (from third onward) equals sum of previous two. So to be a valid selected group, it must be that for all i from 3 to L, a_i = a_{i-1} + a_{i-2}. There's no condition on first two, but they are part of the sequence. So a valid sequence must have length at least 2? Actually even length 2 doesn't violate any condition because there is no i=3. So length 2 is trivially valid. Similarly length 1 is trivially valid. But typically they want maximum contiguous subarray where the condition holds for all positions where possible. In many problems, they treat lengths 1 and 2 as always valid. But the guarantee says "It is guaranteed that Holmes will select atleast 1 or 2 students". That is ambiguous: maybe they guarantee answer >= 2? Actually "select atleast 1 or 2 students" might mean at least 1, or maybe at least 2? The phrase is odd. Could be "at least 1 or 2" means at least 2? Not sure. Let's read the problem statement: "It is guaranteed that Holmes will select atleast 1 or 2 students". Could be typo: "at least 2 students"? In examples, both outputs are 3. So answer can be 1,2,... N.
Given constraints up to 1e5 per test case, we need O(N) per test case.
Simple approach: iterate through array, track current length of valid contiguous segment. Starting from index 0 (0-based). We'll consider subarrays. For each index i >= 2, check if a[i] == a[i-1] + a[i-2]. If true, then we can extend a valid segment. If false, then the condition fails at i; any segment that includes i must break. But we could start new segment at i-1? Since condition only needs previous two. So we can reset the segment start to i-1? Let's think: we need maximum contiguous subarray where for every i >= start+2, condition holds. So we can slide a window.
We can use two-pointer: maintain left index l, and right index r. Initially l=0, r=0. Then expand r. For each step, if r-l >= 2, need to check a[r] == a[r-1] + a[r-2] (within current window). But if we move left, condition might become satisfied? Actually contiguous condition is local. Simpler: iterate through array and keep current length of valid contiguous block. For each i from 2 to N-1, if a[i] == a[i-1] + a[i-2], then we can increment current length? But careful: If we have a block starting at some index, we need to know the start. Standard approach: maintain a variable cur_len. Initially cur_len=1 (since first element). For i=1, we have two elements; no condition to check, so we can set cur_len=2 (if we want). Actually any two consecutive elements are always valid? There's no condition linking them. So we can always extend to length 2 without checking anything. For i >=2, if a[i] == a[i-1] + a[i-2], then we can extend the current block: cur_len++ (where cur_len is length of block ending at i). If condition fails, then the block ending at i cannot be longer than 2? Actually we need to restart a new block starting at i-1? Because the last two elements a[i-1] and a[i] could be start of a new block (since they are length 2). But also a[i] alone could be start, but length 1 is smaller. So after failure, the new block length should be set to 2? Wait, if condition fails at i, then the subarray [..., i] is not valid because at position i the condition is violated. However, the subarray [i-1, i] is valid (since length 2 has no condition). And [i] alone is valid. So we can start a new block at i-1 with length 2? But careful: The block we maintain is contiguous and ends at i. After failure, we can set cur_len = 2, meaning the block consists of a[i-1] and a[i]. Because these two are valid as a block of length 2. But what about a[i-2]? Since condition fails, we cannot include a[i-2]. So resetting to length 2 ensures that for next step i+1, we will check condition using a[i+1] vs a[i] + a[i-1]? That's correct: we need the last two elements of the current block to be a[i-1] and a[i] for checking future. So we set cur_len = 2.
But is there a scenario where after failure, the block length could be 1 instead? Starting from i alone? But then when we move to i+1, we would need last two elements: a[i] and a[i+1]? Actually if we have block length 1 ending at i, then for i+1 we have no two preceding elements to check sum condition; that would only check when block length becomes >=2. Starting with length 2 gives better chance to extend. So setting cur_len=2 is correct.
But wait, consider array: [2,2,4,6,10,...]. Suppose we have failure at some point, but maybe we could have a longer block if we start at i-2? But since condition fails at i, any block that includes both i-2 and i is invalid because condition at i fails. So any block ending at i must not include i-2. The longest block ending at i will be either length 2 (a[i-1], a[i]) or possibly length 1 (a[i]) but length 2 is longer. So indeed reset to 2.
Edge case: if N=1, cur_len=1; max_len=1.
If N=2, max_len=2.
Implementation: Initialize max_len = min(2, N) (since length 2 is always possible if N>=2). But careful: if N=2, answer should be 2. If N=1, answer 1. But our algorithm will iterate from i=2 onward; for N=2, we don't iterate, and we need to set max_len appropriately.
We'll set cur_len = 2 if N>=2 else 1. Then for i from 2 to N-1 (0-indexed, i=2 means third element): if a[i] == a[i-1] + a[i-2], then cur_len++; else cur_len = 2 (since new block of last two). And update max_len = max(max_len, cur_len).
But is cur_len = 2 always valid when we reset? Yes, because two elements always satisfy condition (no condition to violate). But wait: what if N=2, we set cur_len=2. That's fine.
Now check example 1: N=5, arr=[2,3,5,1,2]. Start cur_len=2 (since N>=2). i=2: a[2]=5, a[1]+a[0]=3+2=5 => true, cur_len=3, max=3. i=3: a[3]=1, a[2]+a[1]=5+3=8 ≠1, so cur_len=2. i=4: a[4]=2, a[3]+a[2]=1+5=6 ≠2, cur_len=2 (but after resetting to 2 based on a[3] and a[4]? Actually after i=3, we set cur_len=2 meaning block [a[3], a[3]? Wait we need to be careful: after failure at i=3, we set cur_len=2 meaning the block ends at i=3 and consists of a[2]? No: block ending at i=3: we set cur_len=2 means the block includes indices 2 and 3? Or 3 and something? Let's define precisely: We maintain cur_len as length of longest valid contiguous subarray that ends at the current index i. When we move to next i, we need to know the last two values of that subarray to check condition. So after processing i, cur_len corresponds to subarray ending at i.
So at i=2, cur_len=3, meaning subarray indices 0,1,2.
At i=3: we check condition: does a[3] == a[2] + a[1]? That uses the last two of the previous subarray? If we are extending the previous subarray, we would use a[2] and a[1]. But if we want to consider subarray ending at i=3, we have two possibilities: either we extend the previous valid subarray if condition holds; else we start a new subarray consisting of a[2] and a[3]? Or a[3] alone? But note: the condition for a subarray ending at i that is valid must satisfy that for any j within the subarray where j>= starting index + 2, a[j] = a[j-1]+a[j-2]. If we start a new subarray at i-1, then the subarray indices [i-1, i] is valid. But does that use a[2]? No, it only includes i-1 and i. But in the resetting logic, we should set cur_len = 2 for subarray ending at i, meaning the subarray includes indices i-1 and i. Not i-2. So after failure at i=3, we set cur_len=2 for subarray [2,3]? Wait i-1=2, i=3 => indices 2 and 3. But note: index 2 was part of the previous block. But the new block [2,3] is valid? Check condition: For length 2, no condition. So it's valid. But does it violate anything? The condition would need to be checked only when we extend further. So [2,3] is fine. However, could there be a longer block ending at i=3? Let's see: [1,2,3]? Actually indices 1,2,3: check a[3]=1, a[2]+a[1]=5+3=8 -> false, so invalid. [0,1,2,3] includes condition at i=2 (which is true) and i=3 (false) -> invalid. So longest valid ending at 3 is length 2: either [2,3] or [3] alone but length 2 better. So setting cur_len=2 is correct.
Now at i=4: we need to compute condition to extend the current block ending at i=3 (which is length 2, consisting of indices 2 and 3). To extend to i=4, we need a[4] == a[3] + a[2]? Because the last two of current block are indices 2 and 3 (since block length is 2, the elements are a[2] and a[3]). So we check a[4] == a[3] + a[2]. That is 2 == 1+5 =6? false. So we cannot extend. Then we reset cur_len=2 for subarray ending at i=4, consisting of indices 3 and 4. That length is 2. max remains 3. Works.
Thus algorithm works.
But we have to be careful: after failure, we set cur_len = 2, meaning the new block comprises the previous element and current element. But is it always correct to set cur_len=2? Consider scenario: after failure, maybe there is a block of length 1 that could later become longer? But length 2 is always >=1, so setting to 2 gives longer current ending length. However, we must ensure that the block of length 2 we set indeed ends at current index and is valid. That block consists of indices i-1 and i. That's always valid because there is no condition for two elements. So yes.
But what about scenario where N>=2 and we start from i=2? Suppose a[2] fails condition. Then cur_len was initially 2 (for indices 0,1). After failure, we set cur_len=2 for indices 1,2? Wait initially cur_len=2 for i=1 (or we start with i=1? Let's define loop starting at i=2. We'll have cur_len=2 before loop (meaning subarray ending at index 1 is of length 2). Then for i=2: we check a[2] == a[1] + a[0] (since current block ending at 1 includes indices 0,1). If true, cur_len=3; else cur_len=2 for block ending at 2 (indices 1,2). That's correct.
Now, what about scenario where we have a failure, but the previous block length was 1? That can't happen because we always maintain cur_len>=2 after first two elements? Actually after resetting we set cur_len=2. So cur_len never becomes 1 after we have seen at least two elements. But at start if N=1, cur_len=1. For N>=2, we set cur_len=2. If later we encounter failure, we set cur_len=2 again. So cur_len always stays >=2 after processing at least two elements. This is fine.
But is there a case where the valid block length could be 1 at the end? For example, if N=1, answer 1. For N>=2, we can always have at least length 2, so answer at least 2. The problem statement says "It is guaranteed that Holmes will select atleast 1 or 2 students". That seems consistent: answer at least 2? But they say 1 or 2, maybe ambiguous.
Nevertheless, algorithm yields correct answers for examples.
Now consider edge cases: Large numbers up to 1e9, sum may exceed 32-bit int; but Python can handle big ints.
Time complexity: O(N) per test case.
But before coding, ensure understanding: The condition "number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid." This is with respect to the selected sequence's ordering, not the original indices. So within the contiguous subarray, the indexing is relative: the first kid in the subarray is considered 1st, second is 2nd, etc. So the condition applies to the subarray's own indices. So our algorithm checking a[i] = a[i-1] + a[i-2] for contiguous indices in original array is correct because the subarray must be contiguous and maintain order.
Thus solution: For each test case, read N, read list of N ints. Then if N==1: print(1); continue. Initialize max_len = 2, cur_len = 2. For i in range(2,N): if arr[i] == arr[i-1] + arr[i-2]: cur_len += 1; else: cur_len = 2; max_len = max(max_len, cur_len). Print max_len.
But careful: max_len should be updated after each extension or after reset? After extension we update; after reset we might also want to update max_len because cur_len becomes 2, but max_len is already at least 2. But it's safe to update always.
Edge: if N=2, loop doesn't run, max_len stays 2.
But what about N=0? Not possible.
Double-check with custom tests:
Test: [1,1,2,3,5] => all valid, length 5. cur_len: start=2; i=2: 2==1+1 => cur_len=3; i=3:3==2+1 => cur_len=4; i=4:5==3+2 => cur_len=5; max=5. Output 5.
Test: [1,2,3,4] => i=2: 3==2+1 => cur_len=3; i=3:4==3+2? 3+2=5 !=4 => reset cur_len=2; max=3. Output 3.
Test: [5,5,10,15,25,40,65] => all valid after i=2. Works.
Test: [1,2,4] => i=2: 4==2+1=3? false => cur_len=2; max=2. So answer 2. Is that correct? Let's see: subarrays: [1,2,4] invalid because 4 != 1+2. So longest valid could be [1,2] (len2) or [2,4]? Check [2,4] has no condition? length 2 valid, so yes length 2. So answer 2.
But can there be a longer subarray that starts later? For example [2,4,6]? but we need contiguous. In [1,2,4], [2,4] length2, [4] length1. So max 2.
Now test: [1,2,3,5,8,13] => all valid after i=2: should get length 6.
Now test: [1,2,3,4,7,11] => i=2: 3==2+1 true cur_len=3; i=3: 4==3+2 false => reset cur_len=2 (indices 2,3? Actually after reset cur_len=2 for ending at i=3 means subarray [3,4]? Wait indices:0:1,1:2,2:3,3:4. After failure at i=3, we set cur_len=2 for subarray indices 2,3? That's [3,4]. But check [3,4] length 2 is fine. Then i=4: 7 == a[3]+a[2]? We need last two of current block: current block ending at i=3 is indices 2,3 => a[2]=3, a[3]=4, sum=7 => true, so extend to length3: indices 2,3,4 => [3,4,7] valid? Check 7=4+3 true. So cur_len=3. i=5: 11 == a[4]+a[3]=7+4=11 true, extend to length4: indices2,3,4,5 => [3,4,7,11] valid? 11=7+4 true. So max becomes 4? But is there longer? Subarray [1,2,3] length3, then break, but we have [3,4,7,11] length4. So answer 4. That's correct. So algorithm finds it.
Now test: [1,2,3,5,8,13,21,34] all valid length8.
Now test: [1,2,3,5,8,13,10,23,33] Here after i=6 (value10) check: 10 ==13+8? 21 false, reset cur_len=2 (indices5,6:13,10). Then i=7:23 ==10+13? 23 true, cur_len=3 (13,10,23). i=8:33 ==23+10? 33 true, cur_len=4 (10,23,33). So max maybe 6 from earlier? Actually before failure we had cur_len=6 (indices0..5). So max=6. So algorithm works.
Now test: [1,2,3,5,8,13,21,13,34] etc.
Hence algorithm is correct.
Now consider potential pitfalls: The condition may overflow if using C++ but Python fine.
Now ensure reading input: multiple test cases, first line T. Then for each test case: one line with N, then next line with N integers. So we need to read lines accordingly. N can be up to 1e5, total across test cases up to 1e5? Actually T ≤ 10, N ≤ 1e5 per test, so total could be up to 1e6. Python fine.
Now finalize solution.
But wait: Could there be a scenario where after failure we might need to set cur_len=1 instead of 2? For example, if the previous element is not available? But after failure we always have at least i>=2? Actually at i=2, if failure, we set cur_len=2, which is fine. But what about if N=0? Not possible.
Thus solution is straightforward.
But is there any tricky nuance? The problem says: "number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid." If we consider subarray starting at index l, then for the third element (index l+2) to satisfy: arr[l+2] = arr[l+1] + arr[l]. That's the same as our condition. However, if the subarray length is 2, no condition to check. So our algorithm is correct.
Now, could there be a scenario where the maximal subarray does not start at index 0, and after resetting to cur_len=2, we might miss a longer subarray that starts earlier but does not include the failure point? But because we are scanning sequentially and keeping track of longest valid ending at each position, we effectively consider all subarrays. The longest contiguous valid subarray will have some ending index. Our algorithm computes for each ending index the longest valid subarray ending there. By taking max, we get global max. This is standard.
Thus solution done.
Now think about initial condition: For N=1, we set max_len=1. For N=2, max_len=2.
Implementation:
def max_fib_subarray(arr):
n = len(arr)
if n <= 2:
return n
max_len = 2
cur_len = 2
for i in range(2, n):
if arr[i] == arr[i-1] + arr[i-2]:
cur_len += 1
if cur_len > max_len:
max_len = cur_len
else:
cur_len = 2
return max_len
But need to update max_len in each iteration; else clause may not need update because cur_len is set to 2 and max_len already >=2 but could be 1 if n==1? But for n>=2, max_len already 2. So it's safe to update only when extending, but to be safe, we can update every iteration.
Potential bug: When we extend, we use arr[i-1] and arr[i-2] of the current block? But what if cur_len is not equal to the number of elements from some start? Actually when we extend, we are extending the block that ends at i-1. For that block, the last two elements are indeed arr[i-1] and arr[i-2] because the block is contiguous and includes them. So condition is correct. The cur_len variable just tracks length of the block ending at i-1. When we extend to i, we increment cur_len.
But we need to ensure that after a failure, we set cur_len=2 for block ending at i that consists of arr[i-1] and arr[i]. However, our condition at next step i+1 will use arr[i] and arr[i-1] which are exactly the last two of that block. That works.
One more nuance: When we have a failure at i, we set cur_len=2. But what about the possibility that the block ending at i could be of length 1? Actually length 1 would be smaller, but we want the longest valid ending at i. Could there be a scenario where the block of length 2 is not valid? It is valid because there is no condition. So longest valid ending at i is at least 2, provided i >=1. So we set cur_len=2. But what if i=1? Not possible because we start loop from i=2. After failure at i=2, we set cur_len=2 which uses indices 1 and 2. That's fine.
Thus algorithm works.
But we must ensure that after failure we correctly compute the condition for next i using arr[i-1] and arr[i-2]? For i+1, we will check arr[i+1] == arr[i] + arr[i-1]. That uses the last two of the current block (which is exactly arr[i-1] and arr[i] if cur_len=2). Good.
Edge case: When we have a long valid block, cur_len increments accordingly. At some point, maybe a very long block, but the numbers may become huge; but Python handles it.
Now confirm with additional tests.
Test 1: N=1, arr=[100] => answer 1.
Test 2: N=2, arr=[1,2] => answer 2.
Test 3: N=3, arr=[1,2,4] => answer 2.
Test 4: N=3, arr=[1,2,3] => answer 3.
Works.
Now, is there any scenario where we might need to reset to cur_len=1? For instance, if N=2 and we have [something], no. For N>=2, always cur_len >=2. But consider if N=2 but we had a failure? No failure because we never check. So fine.
Thus solution is ready.
Now, potential pitfalls: The input might have spaces and newlines; use sys.stdin.read() to parse all ints. Since T up to 10 and N up to 1e5, reading all ints into list and processing sequentially is fine.
We'll write code: read integer T. Then for each test case, read N, then read N ints. Process.
We can pre-read all ints from sys.stdin to avoid line by line issues.
Implementation plan:
import sys
def solve():
data = list(map(int, sys.stdin.read().split()))
it = iter(data)
T = next(it)
out = []
for _ in range(T):
N = next(it)
arr = [next(it) for _ in range(N)]
if N <= 2:
out.append(str(N))
else:
max_len = 2
cur_len = 2
for i in range(2, N):
if arr[i] == arr[i-1] + arr[i-2]:
cur_len += 1
if cur_len > max_len:
max_len = cur_len
else:
cur_len = 2
out.append(str(max_len))
sys.stdout.write("\n".join(out))
if name == "main":
solve()
But careful: The case N <= 2 includes N=0? Not possible.
Now test with example:
Input:
2
5
2 3 5 1 2
3
1 2 3
Our code: T=2, first N=5, arr=[2,3,5,1,2] => as computed max_len=3. second N=3, arr=[1,2,3] => loop i=2: 3==2+1 => cur_len=3, max_len=3. output 3 and 3. matches.
Now, consider a test with N=1: input "1\n1\n5". Output "1". Good.
Now, any other hidden complexities? Possibly the problem expects that for length 2, the condition is not required, but they might require at least 3? Let's read statement again: "He will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition". The condition is "number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid." For a sequence of length 2, there is no i that is 3 or greater, so the condition is vacuously true? Typically in such problems, a sequence of length less than 3 is considered valid because there is no violation. However, some problems might require the condition to hold for all i from 1? But that doesn't make sense because for i=1 and i=2 there are no previous two. Usually it's considered valid if the condition holds for all i where i-1 and i-2 exist. So length 1 and 2 are automatically valid.
But what about the guarantee: "It is guaranteed that Holmes will select atleast 1 or 2 students". This might imply that the answer will be at least 2? Or at least 1? In the sample, both are 3, but they say at least 1 or 2. Could be typo: "at least 2 students". In any case, our solution covers both.
Now, could there be a scenario where the longest valid subarray is of length 1? That would happen if N=1. Or if N>1 but all adjacent pairs are not part of any valid length>1? Actually any pair of consecutive numbers forms a valid subarray of length 2. So for N>=2, the answer cannot be 1 because there is always at least a subarray of length 2 (any two consecutive kids) that is valid. So answer for N>=2 is at least 2. Therefore, the guarantee "at least 1 or 2" likely means at least 2. So our algorithm's answer for N>=2 will be at least 2, which is correct.
But what about the case where N=0? Not possible.
Thus all good.
Now complexity: O(N) time per test case, O(1) extra.
Now before finalizing, consider if the problem might ask for subsequence (not necessarily contiguous). The phrase "arrange themselves in such a way that, number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid. Now they have arranged themselves in an order." It implies they arranged themselves in a line, so the order is the line. Sherlock selects a sequence of kids such that the condition holds. Typically "sequence" in such problems might mean a subsequence (not necessarily contiguous). But the phrase "arranged themselves in an order" and then "select a sequence of kids" often means contiguous, because they are standing in a line and you can pick a contiguous group. Also the example: For array [2,3,5,1,2], they said the maximum number of kids is 3, that is indices 1 to 3 (contiguous). If subsequence were allowed, you could pick [2,3,5] still contiguous, but maybe you could pick [2,3,5,?] no. But could you pick [2,5,?] Not valid. So subsequence would not give longer than contiguous? Actually consider [2,3,5,1,2] maybe you could pick [2,3,5,?] can't extend. But what about [2,5,7]? Not contiguous. But condition would be: For subsequence, you would consider relative indices in subsequence. For example, if you pick indices 0,2,4: values 2,5,2 -> check: 5? Actually for subsequence, you need to maintain order but can skip. Condition: for the third element (5) it should be sum of first two (2+? we have only two before: 2 and something?). Actually if you pick indices i<j<k as subsequence, then the third kid (at index k) should equal sum of second (j) and first (i)? That would be a different condition: The condition is based on positions within the selected sequence, not original indices. So for subsequence, you would need a[k] = a[j] + a[i]. That is not necessarily contiguous. But then longest subsequence might be longer than contiguous? Possibly. For example, array [1,2,3,4,7,11] could we pick [1,3,4,7,11]? Check: 3? Actually first three: 1,3,4 -> 4 = 3+1? yes. Then 7 = 4+3? yes. Then 11 = 7+4? yes. So length 5, while contiguous max is 4 ([3,4,7,11]). So subsequence could be longer. But the example output for [2,3,5,1,2] is 3. Could there be a longer subsequence? Check: [2,3,5] is length 3. Could we do [2,5,7]? No 7 not present. [3,5,8]? No 8. [2,1,3]? 3=1+2, yes but order? indices: 0:2, 3:1, 4:2 -> 2+1=3? Not equal to 2. So no. [2,3,5,?] can't. So maximum subsequence might also be 3. But the second example [1,2,3] yields 3. If subsequence, could we pick longer? No.
But if they meant subsequence, they'd likely phrase "subsequence" not "sequence". However, sometimes "sequence" can be ambiguous. In competitive programming, "subsequence" typically means not necessarily contiguous, while "subarray" means contiguous. Here they say "sequence of kids" and also "arrange themselves in such a way that..." then "select a sequence of kids such that the length of the sequence is maximized". It might be contiguous because they arranged themselves in a line and we need to pick a contiguous group that satisfies the rule. Additionally, the example matches contiguous.
Also note: The problem mentions "since there can be many such small groups among the entire N kids", implying groups (contiguous segments) rather than arbitrary subsequences.
Thus contiguous is correct.
We should also check if the problem might require that the entire selected group should satisfy the condition for all i >= 3, meaning the first two are free. Our algorithm does that.
Now, another nuance: The condition "number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid." If we have a subarray of length L, then for i=3,...,L we need a_{l+i-1} = a_{l+i-2} + a_{l+i-3}. That's exactly our check.
Thus solution is straightforward.
Now, verify for large N and edge cases with repeated numbers? For instance, [0,0,0,0,0] => condition: 0 = 0+0 true, so entire array works, length N. Our algorithm: cur_len starts 2, then for each i, condition holds, cur_len increments, max_len = N. Good.
Now, negative numbers? Not possible because chocolates count ≥ 1. So positive.
Now, we must handle up to 1e5 per test, T up to 10, total up to 1e6, which is fine.
One more thing: The input line for N might be on same line as previous? Usually each test: one line with N, then next line with N numbers. But using split we ignore line breaks, so fine.
Now, consider if there are multiple spaces, still fine.
Now, potential bug: For N=0? Not possible.
Now, produce final solution.
But wait, there's a nuance: Our cur_len variable, after resetting to 2, we use arr[i-1] and arr[i-2] for next condition. However, what if the failure occurs and the new block of length 2 starts at i-1 and i, but for the next i+1 we need to check arr[i+1] == arr[i] + arr[i-1]. That's exactly using the two elements of the new block. Good.
But one more nuance: After resetting, we set cur_len=2. But we must ensure that when we later extend, we increment cur_len accordingly. That works.
Now, consider scenario: After a failure, we might have a valid block of length 2 (i-1,i). But it's possible that the block could also be of length 1? But 2 is longer, so okay.
Now, double-check with a tricky case: arr = [1,3,2,5,7,12] Let's simulate:
i=2: 2 == 3+1? 4 false -> cur_len=2 (indices1,2: [3,2])
i=3: check a[3]=5 vs a[2]+a[1]=2+3=5 true -> cur_len=3 (indices1,2,3: [3,2,5])
i=4: check a[4]=7 vs a[3]+a[2]=5+2=7 true -> cur_len=4 ([3,2,5,7])
i=5: check a[5]=12 vs a[4]+a[3]=7+5=12 true -> cur_len=5 ([3,2,5,7,12]) -> max_len=5. But is this valid? Check: 5=2+3 yes, 7=5+2 yes, 12=7+5 yes. So yes it's valid. However, note that the starting index is 1, not 0. So algorithm found it. But what about earlier possible longer? Starting at index0: [1,3,2]? 2 != 3+1 so not valid. So max is 5. Works.
Now, what about case where after failure, the new block of length 2 might actually be part of a longer valid block that starts earlier but skips a problematic element? That's not allowed because contiguous. So fine.
Thus algorithm is correct.
Now implement.
But wait, there's a subtlety: The condition must hold for all i from 3 to L. However, our algorithm ensures that for each extension, the condition holds relative to the immediate last two elements of the current block. But does this guarantee that the entire block satisfies the condition? Yes, because we build it incrementally: if we have a valid block ending at i-1, and we check condition for adding i using the last two of that block, then the new block is valid as well. Induction ensures all positions satisfy.
Now, one more nuance: Suppose we have a block that is valid, but after a failure we set cur_len=2 for block ending at i. However, could there be a block ending at i that is longer than 2 but not using the immediate previous two elements? For instance, maybe the block [a,b,c] where c = a + b? But if we have a failure at i, that means the condition with the previous two (i-2,i-1) fails. However, perhaps a longer block ending at i could start earlier than i-1 but skip some elements? That would not be contiguous. So no.
Thus all good.
Now we can code.
But there is a potential twist: The problem statement says "He will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition". Could "sequence" mean not necessarily contiguous? Many problems use "subsequence" for non-contiguous and "subarray" for contiguous. But here they say "sequence". Also they say "arrange themselves in such a way". They arranged themselves in an order. Then Sherlock selects a sequence of kids. Usually in array problems, "subsequence" means not necessarily contiguous. However, the phrase "there can be many such small groups among the entire N kids" suggests groups (contiguous). Also the example indicates contiguous. Also typical problem known as "Longest Fibonacci-like subarray" or "Longest Fibonacci subsequence"? There is a known problem "Length of Longest Fibonacci Subsequence" which is subsequence (non-contiguous). But that problem is more complex, often solved with DP O(N^2) or O(N log M). However, here N up to 1e5, so O(N^2) would be too slow. So it must be contiguous. And the solution O(N) is trivial. So it's likely contiguous.
Thus we stick.
Now confirm with sample: matches.
Now consider if there is any other interpretation: Could the selection be any sequence (not necessarily contiguous) but they maximize length, and guarantee answer at least 2? That would be a harder problem. But constraints N up to 1e5, if subsequence, we need to find longest Fibonacci-like subsequence (where each term is sum of previous two). That's similar to LeetCode 873. Length of Longest Fibonacci Subsequence. The best known solutions are O(N^2) using DP with hash map, and N up to 1000 typically. But here N up to 1e5, O(N^2) is impossible. So it must be contiguous. Also the problem statement says "groups" and "arrange themselves" implying contiguous.
Thus our solution is correct.
Now we can finalize.
But before finalizing, I'll double-check the input format: "First line is an integer T which denotes the total number of test cases. Each of the next T lines contains an integer N which denotes, N students. The next line contains N spaced integers." That suggests for each test case, we have two lines: one with N, next with N ints. So there are T pairs of lines. Our parsing with split works.
Now edge: There might be extra blank lines? Unlikely.
Now time to produce final answer.
But let's also consider if there could be multiple test cases where N=0? Not.
Thus solution is done.
Now produce final answer.
But to be thorough, let's test some random arrays manually via code mental.
Case: N=6, arr = [1,2,3,5,8,13] -> cur_len=2, i=2 true cur_len=3, i=3 true cur_len=4, i=4 true cur_len=5, i=5 true cur_len=6, max=6.
Case: [1,2,4,6,10,16] -> i=2:4==2+1? 3 false -> cur_len=2 (2,4). i=3:6==4+2? 6 true -> cur_len=3 (2,4,6). i=4:10==6+4? 10 true -> cur_len=4 (2,4,6,10). i=5:16==10+6?16 true -> cur_len=5 (2,4,6,10,16). So max=5. But also possible [1,2,3,5,8,13] would give longer. So fine.
Case: [2,2,4,6,10,16] -> i=2:4==2+2 true -> cur_len=3; i=3:6==4+2 true -> cur_len=4; i=4:10==6+4 true -> cur_len=5; i=5:16==10+6 true -> cur_len=6 -> max=6.
Now what about when the sum condition holds but the block is interrupted by a failure? Already covered.
Now, what about large numbers leading to overflow? Python fine.
Thus solution done.
Now, finalize.
But before finalizing, note: Some solutions might need to consider that the sequence could start at any point, not necessarily at index 0, but our DP covers that.
Now produce final answer.
Edge case: N=2, arr = [1,2] -> output 2.
Edge: N=3, arr = [1,1,2] -> i=2:2==1+1 true -> cur_len=3 -> output 3.
Edge: N=3, arr = [1,1,1] -> 1 !=1+1? Actually 1 != 2, so false -> cur_len=2 -> output 2. That's correct because longest valid contiguous subarray is either [1,1] (len2) or [1,1] but [1,1] is valid, [1,1,1] invalid. So answer 2.
Now what about [1,1,2,3,5] -> all valid, answer 5.
Now for [5,5,10,15,20] -> i=2:10==5+5 true cur_len=3; i=3:15==10+5 true cur_len=4; i=4:20==15+10? 25 false -> cur_len=2; max=4. So answer 4.
Now all good.
Thus final answer.
We'll present code with function solve().
Now, possible memory optimization: we don't need to store entire array; we could process on the fly, but we need to look back two elements. Since we need to check arr[i] against arr[i-1] and arr[i-2], we can keep two previous values. But we also need to know arr[i-1] and arr[i-2] when resetting. Actually after resetting, we set cur_len=2, and for next check we need arr[i] and arr[i-1] (the last two). So we can keep a sliding window of last two values. But we also need to know the length of current valid block, which we track. But we don't need the entire array if we just compute on the fly. However, reading all into list is fine given constraints.
But to be safe for memory, we can process streaming. Not needed.
Now produce final answer in required format.
But wait, the problem might be from CodeChef or similar, and they often require to print answer per test case.
Now, final code.
But let's also consider if T is large, reading with sys.stdin.read is efficient.
One more nuance: In Python, using sys.stdin.read().split() reads all ints, but if input is huge, it's fine.
Now output: each answer on new line.
Now final.
But I recall a known problem "FIBOSEQ" or something similar. Possibly they want to handle subsequence? Let's verify with constraints: N up to 1e5, T up to 10. For subsequence, typical solution O(N^2) is too slow, but there might be O(N log M) solution? For Fibonacci-like subsequence, the standard approach is DP with two preceding indices, O(N^2) time, O(N^2) memory, which is impossible for N=1e5. However, there is a known problem "Length of Longest Fibonacci Subsequence" with N up to 1000. So given N up to 1e5, it's definitely contiguous.
Also the phrase "groups" and "arrange themselves" suggests contiguous.
Thus final answer.
But the problem statement: "Now to test their team chemistry and IQ skills, Watson told the lads to arrange themselves in such a way that, number of chocolates of the ith kid should be equal to the sum of (i-1)th kid and (i-2)th kid. Now they have arranged themselves in an order." This describes the entire arrangement they attempted. Then "Now Sherlock announced that he will select the students who have formed the line according to this order. But since there can be many such small groups among the entire N kids, he will select a sequence of kids such that the length of the sequence is maximized, meanwhile satisfying the above condition". So the kids attempted to arrange themselves according to the rule, but they might not have fully succeeded. Sherlock will select those who have formed the line according to this order. Since there can be many small groups among the N kids, he will select a sequence of kids such that the length is maximized. That implies he looks for a contiguous subsequence that satisfies the rule (since the line is physical). So contiguous.
Thus solved.
Now I'll provide final answer.
But I'll include comments in code for clarity.
We'll produce the solution.
One more thing: In the code, for N<=2 we simply output N. Else we loop.
But what about N=0? Not.
Now final.
But wait, what about the possibility that the condition must hold for all i from 1? Some interpretations: The ith kid means the position in the selected group, but i starts from 1. For i=1 and i=2, there is no previous two, so condition vacuously true. That's fine.
Thus solution stands.
Now I'll produce final answer.
```python
import sys
def solve() -> None:
data = list(map(int, sys.stdin.read().split()))
it = iter(data)
t = next(it)
out_lines = []
for _ in range(t):
n = next(it)
arr = [next(it) for _ in range(n)]
if n <= 2:
out_lines.append(str(n))
continue
# at least two elements exist
max_len = 2
cur_len = 2 # length of valid subarray ending at the previous index (i-1)
for i in range(2, n):
if arr[i] == arr[i-1] + arr[i-2]:
cur_len += 1
if cur_len > max_len:
max_len = cur_len
else:
cur_len = 2 # start a new valid block of the last two elements
out_lines.append(str(max_len))
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()