We need to understand the problem. Chef has N cupcakes. He chooses an integer A between 1 and N inclusive. He puts exactly A cupcakes into each package. He makes as many packages as possible. So the number of packages he can make is floor(N / A). He then gets to eat the remaining cupcakes, which is N mod A, i.e., N - floor(N/A)*A = N % A. He wants to maximize the remainder. If multiple A yield the same remainder, he wants the largest A.
We need to output the A that maximizes the remainder, with tie-breaking to largest A.
Given constraints: N up to 10^8, T up to 1000. So per test case we can do O(sqrt(N)) maybe, but cannot iterate over all A (N up to 1e8, 1000 test cases worst-case sum maybe 1e8? That might be borderline but perhaps O(N) per test case is too slow. But we can derive a formula.
We need to maximize N mod A, i.e., remainder when N divided by A. For given N, the remainder can be at most A-1. However, we can choose any A.
Observation: For a given N, the maximum possible remainder is ceil(N/2) - 1? Actually, consider A > N: not allowed (A ≤ N). Let's think: For a given A, remainder = N - floor(N/A)*A. This is like N mod A.
What is the maximum possible N mod A for A from 1 to N? It is well known that the maximum remainder is N - 1 when A = N? Wait: When A = N, floor(N/N)=1, remainder = N - 1*N = 0. So not. Actually, remainder can be up to N-1? For A = 1, remainder = 0 because N mod 1 = 0. For A = 2, remainder is 0 or 1 depending on N parity. For A = N-1, remainder = N mod (N-1) = 1 if N>1. Actually, N mod (N-1) = 1. For A = floor(N/2)+1, remainder? Let's consider A > N/2: Then floor(N/A)=1, remainder = N - A. So if we take A just above N/2, remainder = N - A which is less than N/2. The maximum remainder in that region occurs at the smallest A giving floor(N/A)=1, i.e., A = floor(N/2)+1? Actually, for A > N/2, we have 1 ≤ A ≤ N? If A > N/2, then 2A > N, so floor(N/A)=1, remainder = N-A. This is decreasing as A increases. So the maximum remainder among A > N/2 is at the smallest A in that range, i.e., A = floor(N/2)+1. That gives remainder = N - (floor(N/2)+1) = ceil(N/2)-1. For even N, say N=10, floor(N/2)=5, so smallest A >5 is 6, remainder=4. For odd N, N=11, floor(N/2)=5, A=6 gives remainder 5. So max remainder among A > N/2 is floor((N-1)/2)? Actually ceil(N/2)-1.
Now for A ≤ N/2, floor(N/A) ≥ 2. We need to consider if we can get remainder larger than that. For some A, remainder might be up to A-1, which could be as high as near N/2 -1 if we pick A close to N/2. But the maximum remainder from A > N/2 is N - A (which is < N/2) and can be as high as about N/2 -1 for odd N and N/2-? For even N, N/2? For N even, A = N/2+1 gives remainder = N/2 -1; A = N/2 gives floor(N/(N/2)) = 2, remainder = 0. So the maximum remainder from A > N/2 is about N/2 -1. But can we get remainder larger? Suppose we pick A = floor(N/2). Then remainder = N mod (N/2) = 0 if N even, or 1 if N odd? Actually for N even: N = 2k, A = k gives remainder = 0; for N odd: N=2k+1, A=k gives remainder = (2k+1) mod k = 1. So not large.
What about A around sqrt(N)? Let's try to find maximum possible remainder. The remainder can be at most A-1, so to get a large remainder we need A large, but if A is large (close to N), remainder is N - A, which is small. If A is small, remainder max is A-1, which is small. So there's a tradeoff: The maximum possible remainder is when A is around N/2? Actually, consider we want to maximize min(A-1, N - A?) Not exactly.
Think of it as: For any A, remainder = N - q*A where q = floor(N/A). So it's like the distance to the nearest multiple of A less than N. It's known that the maximum remainder is less than A, and also less than N - A if q=1? Not always. In general, the remainder can be as high as up to floor(N/2) for some N? Let's test small N manually.
For N=2: possible A=1: remainder 0; A=2: remainder 0. So max remainder=0, best A=2 (largest tie). Output 2 matches.
N=3: A=1->0; A=2->1; A=3->0. Max remainder=1 at A=2. Also A=??? So output 2. But sample N=5 outputs 3. Let's test N=5: A=1->0; 2->1; 3->2; 4->1; 5->0. Max remainder=2 at A=3. So output 3. Good.
N=6: A=1->0; 2->0 (since 6 mod 2 =0); 3->0; 4->2; 5->1; 6->0. Max remainder=2 at A=4. Also A=?? A=5 gives 1; A=4 gives 2. So output 4. Check maybe A=?? So A=4 yields remainder 2. Is there any A giving remainder 3? A=5 gives 1; A=3 gives 0; So max=2. So answer 4.
N=7: A=1->0;2->1;3->1;4->3;5->2;6->1;7->0. Max remainder=3 at A=4. Also A=?? 4 gives 3. So output 4. N=8: A=1->0;2->0;3->2;4->0;5->3;6->2;7->1;8->0. Max remainder=3 at A=5. So output 5. N=9: A=2->1;3->0;4->1;5->4;6->3;7->2;8->1;9->0; A=1->0. So max remainder=4 at A=5. Also A=?? 5 gives 4; 6 gives 3; So output 5.
N=10: A=4->2;5->0;6->4;7->3;8->2;9->1;10->0; also 3->1;2->0;1->0. Max remainder=4 at A=6. So output 6? Let's check: A=6 gives remainder 4, A=?? 7 gives 3; 8 gives 2; So yes 6. For N=10, maximum remainder=4, A=6.
Observations: The maximizing A seems to be floor(N/2)+1? For N=5, floor(5/2)=2, +1=3 -> matches. N=6, floor(6/2)=3, +1=4 -> matches. N=7, floor(7/2)=3, +1=4 -> matches. N=8, floor(8/2)=4, +1=5 -> matches. N=9, floor(9/2)=4, +1=5 -> matches. N=10, floor(10/2)=5, +1=6 -> matches. N=2, floor(2/2)=1, +1=2 -> matches (but remainder 0, but we need largest A with tie? Actually for N=2, all A give remainder 0, and A=2 is largest, and floor(N/2)+1=2, which matches). N=3, floor(3/2)=1, +1=2 -> matches. N=4? Let's test N=4: A=1->0;2->0;3->1;4->0. So max remainder=1 at A=3. floor(4/2)=2, +1=3 -> matches. So pattern holds for these.
But is it always the case that the A that maximizes remainder is floor(N/2)+1? Let's test other N like N=11: floor(11/2)=5, +1=6. Compute remainders: A=6 -> 11 mod 6 =5; A=7->4; A=5->1; A=8->3; A=9->2; A=10->1; A=11->0; So max remainder=5 at A=6. Could there be an A that yields remainder 5 or higher? A=6 yields 5, A=7 yields 4, A=4 yields 3? Actually A=4 -> 11 mod 4=3. A=12 not allowed. So 5 is max. So works.
N=12: floor(12/2)=6, +1=7 -> remainder 12 mod 7=5. Check A=8 -> 4; A=5->2; A=6->0; A=7->5; A=9->3; A=10->2; A=11->1; A=12->0; So max remainder=5 at A=7. Could A=13? Not allowed. So fine.
N=13: floor(13/2)=6, +1=7 -> remainder 13 mod 7=6. A=8 ->5; A=9->4; A=10->3; A=11->2; A=12->1; A=13->0; So max remainder=6 at A=7.
But is there any case where another A yields a larger remainder than floor(N/2)+1? Let's think theoretically.
We need to maximize f(A) = N - floor(N/A) * A. Let's denote q = floor(N/A). Then remainder = N - qA. Note that q = floor(N/A) implies q ≤ N/A < q+1, so A ∈ (N/(q+1), N/q]. For a fixed q, remainder = N - qA, which is decreasing in A (since -q coefficient). So for a given q, to maximize remainder, we should take the smallest A in that interval (i.e., just greater than N/(q+1)). But note that A must be integer, so A_min = floor(N/(q+1)) + 1, provided that this A ≤ N/q. The remainder at that A is N - q*(floor(N/(q+1))+1). But maybe we can simplify.
But perhaps it's simpler: We suspect that the maximum remainder occurs for q=1. Because when q=1, remainder = N - A, and we can choose A > N/2. That gives remainder up to about N/2 - 1. For q≥2, remainder ≤ A-1 (since remainder < A) and A ≤ N/2 (since q≥2 => A ≤ N/2). So max remainder for q≥2 is at most A-1 ≤ N/2 - 1. So the maximum possible remainder overall is at most N/2 - 1? Actually, for odd N, N/2 is fractional, so floor(N/2)? Let's check: If N is odd, say 9, N/2 = 4.5, N/2 -1 = 3.5, but we got remainder 4 from A=5 (q=1). So remainder=4 > 3.5? But 4 is floor(N/2) ? For N=9, floor(N/2)=4, remainder=4 is exactly floor(N/2). But we earlier thought max remainder from q=1 is ceil(N/2)-1, which for N=9: ceil(9/2)=5, minus 1 = 4. So that matches. For even N=10, ceil(10/2)=5, minus 1=4, remainder=4. So max remainder from q=1 is ceil(N/2)-1. For q≥2, remainder ≤ A-1 and A ≤ N/2, so max remainder ≤ floor(N/2) - 1? Because if A ≤ N/2, then A-1 ≤ N/2 -1. For even N, N/2 is integer, so max remainder ≤ N/2 -1. For odd N, floor(N/2) = (N-1)/2, so max remainder ≤ floor(N/2) - 1? Actually A ≤ floor(N/2) because if q≥2 then A ≤ N/2 (strictly? For integer A, if N is odd, say 9, A ≤ 4.5 => A ≤ 4). So A ≤ floor(N/2). Then remainder ≤ A-1 ≤ floor(N/2)-1. For N=9, floor(N/2)=4, remainder ≤ 3 from q≥2. But we found remainder=4 from q=1. So q=1 yields larger remainder if ceil(N/2)-1 > floor(N/2)-1, which is true when N is odd (since ceil(N/2)-1 = floor(N/2) because ceil(N/2)=floor(N/2)+1 for odd N). For even N, ceil(N/2)-1 = N/2-1, and floor(N/2)-1 = N/2-1, so they are equal. But we must also consider that for q≥2, can we achieve remainder exactly N/2 -1? Let's test even N=10: floor(N/2)=5, so from q≥2, we need A such that remainder = A-1 = 4, so A=5. But if A=5, then q = floor(10/5)=2, remainder=0 (since 10 mod 5 =0). So can't get remainder 4. For A=6, q=1, remainder 4. So from q≥2, max remainder might be less than N/2-1. For N=10, from q≥2: A=4 gives remainder 2; A=3 gives 1; A=2 gives 0; So max remainder from q≥2 is 2? Actually A=4 gives remainder 2; A=6 is q=1. So indeed maximum remainder is from q=1. So for even N, the maximum remainder from q=1 is N/2 -1, and from q≥2 it's less, so overall max is from q=1. For odd N, max from q=1 is floor(N/2), and from q≥2 it's at most floor(N/2)-1, so q=1 yields strictly larger. So indeed the maximum remainder is achieved when q=1, i.e., A > N/2. And among those A, remainder = N - A, which is decreasing in A. So the maximum remainder is achieved at the smallest A in the range (N/2, N], i.e., the smallest integer greater than N/2, which is floor(N/2) + 1. That yields remainder = N - (floor(N/2)+1) = ceil(N/2) - 1. For even N, ceil(N/2) = N/2, so remainder = N/2 - 1. For odd N, ceil(N/2) = (N+1)/2, so remainder = (N+1)/2 - 1 = (N-1)/2 = floor(N/2).
Thus the maximizing A is floor(N/2)+1. But wait, what about ties? If multiple A yield the same maximum remainder, we must choose the largest such A. Is it possible that other A besides floor(N/2)+1 also achieve the same remainder? For even N: N=10, floor(N/2)+1=6 gives remainder 4. Are there other A with remainder 4? Check A=7: remainder 3; A=5: remainder 0; A=8: 2; A=9:1; A=10:0; A=... Actually A=11 not allowed. So only A=6 yields 4. For N=6: floor(3)+1=4 gives remainder 2. Check A=5: remainder 1; A=7 not allowed. So only A=4. For N=12: A=7 gives remainder 5. Check A=8: remainder 4; A=6:0; So only A=7. For odd N: N=9, A=5 gives remainder 4. Check A=6: remainder 3; A=4: remainder 1; So only A=5. For N=5, A=3 gives remainder 2; A=4 gives remainder 1; So only A=3. So it seems unique? But maybe there are cases where two different A yield same remainder? Let's test N=2: All A give remainder 0, so many ties. floor(2/2)+1 = 2, and 2 is largest among them, so that matches the tie-breaking rule (print largest such size). For N=1? But constraints N≥2, so N=1 not considered. But still, N=2 is a special case where the maximum remainder is 0 and all A give 0, so floor(N/2)+1=2 works as largest. What about N=3? All A? A=2 gives remainder 1, A=1 and 3 give 0. So only A=2 gives max remainder 1, floor(3/2)+1=2, fine.
But could there be a scenario where more than one A yields the same maximal remainder? Possibly when N is such that remainder = N - A is the same for two A? That would require N - A1 = N - A2 => A1=A2, so no. So for q=1, remainder = N - A is strictly decreasing with A, so each A gives unique remainder. For q≥2, remainder can be the same for different A? Possibly. But if the maximum remainder is achieved by some A with q≥2, then that maximum must be at least as large as any remainder from q=1. We argued that for even N, the maximum from q=1 is N/2 - 1, and from q≥2 it's at most N/2 -1, but could be equal. However, is it possible that some A with q≥2 gives remainder exactly N/2 - 1? That would require N mod A = N/2 -1. For N even, N/2 -1 is odd? Not necessarily. Let's try to find example. Suppose N=8, N/2 -1 = 3. Do we have any A with q≥2 giving remainder 3? A=5? q=1 (since 5>4? Actually 8/2=4, so A=5 >4 gives q=1, remainder 3. For q≥2, A≤4. For A=4, remainder 0; A=3, remainder 2; A=2,0; A=1,0. So max from q≥2 is 2. So not equal.
N=10, N/2 -1=4. A=6>5 gives q=1 remainder 4. For q≥2, A≤5. A=5 remainder 0; A=4 remainder 2; A=3 remainder 1; So max=2.
N=12, N/2 -1=5. A=7>6 gives remainder5. A≤6: A=6 rem0; A=5 rem2; A=4 rem0; So max=2.
N=14: N/2-1=6. A=8>7 gives remainder6? 14 mod 8=6. A≤7: A=7 rem0; A=6 rem2; A=5 rem4? Actually 14 mod5=4; A=4 rem2; A=3 rem2; So max=4<6. So seems q=1 gives larger.
But what about N=2? N/2 -1 =0. All A give remainder 0. So q≥2? A=1? But q = floor(2/1)=2, remainder 0. So maximum remainder 0, and both A=1 (q=2) and A=2 (q=1) give remainder 0. So there are ties. floor(N/2)+1=2 is largest, correct.
What about N=4? N/2 -1 =1. A=3>2 gives remainder1. A=2 gives remainder0; A=1 remainder0. So unique.
So it seems that for N>2, the maximum remainder is unique and achieved at A = floor(N/2)+1. For N=2, it's still the same answer.
But wait, maybe there is an edge case: N=0? Not.
Let's test N=100: floor(50)+1=51, remainder 49. Could there be A with q≥2 giving remainder 49? That would require A>49? Actually if q≥2, A ≤ 50. For remainder 49, we need A such that N mod A = 49, and A ≤ 50. The maximum remainder < A, so if remainder 49, then A > 49, so A could be 50. Check A=50: 100 mod 50 = 0, not 49. A=49: remainder 2 (since 100 mod 49 = 2). A=51 is q=1 remainder 49. So no. So unique.
But consider N=6 again we did.
Thus answer seems to be simply floor(N/2) + 1.
But wait, is there any scenario where A = floor(N/2)+1 does not give the largest A among ties? Since it's likely the only maximum, it's also the largest. But what if there is another A > floor(N/2)+1 that gives same remainder? For q=1, remainder = N - A, so as A increases, remainder decreases. So no two A > N/2 yield same remainder (except if N is same? N-A1 = N-A2 => A1=A2). So no. For A ≤ N/2, could they give the same remainder as the maximum? For that to happen, the maximum remainder from q=1 would be equal to some remainder from q≥2. As argued, for N even, maybe if some A ≤ N/2 yields remainder = N/2 -1. But then we need N mod A = N/2 -1. Since A ≤ N/2, remainder < A, so N/2 -1 < A ≤ N/2. This implies A could be N/2 (if N/2 -1 < N/2, always true). Let's test A = N/2. Then N mod (N/2) = 0 if N even, because N is multiple of N/2. So remainder 0. Not N/2 -1. What about A = N/2 - 1? Then A ≤ N/2, but remainder? For N=10, A=4 gave remainder 2, not 4. For A = N/2 - 1, remainder is N mod (N/2 - 1). That could be? But we want it equal to N/2 -1. That would mean N mod A = A, which is impossible because remainder < A. So cannot. So no A ≤ N/2 can give remainder equal to N/2 -1 because that would require remainder = N/2 -1, but remainder < A ≤ N/2, so if remainder = N/2 -1, then A must be > N/2 -1, i.e., at least N/2. The only integer A > N/2 -1 and ≤ N/2 is A = N/2 (if N even). But as we saw, remainder is 0, not N/2 -1. So impossible. So for even N, the maximum remainder from q=1 is strictly greater than any remainder from q≥2. For odd N, max remainder from q=1 is floor(N/2) = (N-1)/2. For q≥2, remainder ≤ A-1 ≤ floor(N/2)-1 = (N-1)/2 -1, so strictly less. So indeed unique.
Thus answer is A = floor(N/2) + 1.
But wait, check N=1? Not in constraints. N=2 works.
So solution: For each test case, output (N//2 + 1). In integer division.
But let's double-check with sample: N=2 -> 2//2+1=1+1=2 OK. N=5->5//2+1=2+1=3 OK.
Edge cases: N=10^8 (even) -> output 50000000+1=50000001? Actually floor(100000000/2)=50000000, +1 = 50000001. That's within range.
Now time complexity O(T). That's trivial.
But is there any subtlety? The problem statement: "Chef will choose an integer A between 1 and N, inclusive, and place exactly A cupcakes into each package. Chef makes as many packages as possible. Chef then gets to eat the remaining cupcakes." So number of packages = floor(N/A). He wants to maximize leftovers. We argued that maximum leftovers = ceil(N/2)-1? Actually we want to choose A to maximize N mod A. The maximum possible remainder is indeed (N-1)/2 for odd N, and N/2 - 1 for even N. That is less than N/2 always? For N even, N/2 -1. So answer A = floor(N/2) + 1.
But is there any possibility that A = floor(N/2) + 1 is not the largest A when ties? As we argued, ties only when maximum remainder is 0, i.e., when N=2? Or N=1? But also perhaps N=3? Max remainder 1 > 0. So only N=2 yields all zeros? Let's test N=1 (if allowed) would have A=1 remainder 0 only, tie? But not. Maybe N=2 is the only case where all remainders are 0? Check N=2: A=1 -> 0, A=2 -> 0. For N>2, there is always at least one remainder positive? Actually N=3 gives remainder 1 positive. For N=4 gives remainder 1 positive. So for N>2, the maximum remainder >0, and we argued it's unique. Let's test N=6: max remainder=2 >0, unique. So only N=2 has all zero remainder? But what about N=3? Actually N=3 yields A=2 remainder1, others 0, so max=1 unique. N=4: A=3 remainder1, others 0, unique. N=5: A=3 remainder2, unique. So yes.
Thus answer: print N//2 + 1.
But wait, let's prove more formally: For any A, remainder r = N mod A. Consider two cases.
Case 1: A > N/2. Then floor(N/A)=1, r = N - A. This is decreasing in A. So to maximize r, we want smallest A in this range, i.e., A = floor(N/2) + 1. The maximum r in this case is N - (floor(N/2)+1) = ceil(N/2) - 1.
Case 2: A ≤ N/2. Then floor(N/A) ≥ 2. Then r = N - kA for some k ≥ 2. Since kA ≤ N, we have r = N - kA < A (since kA > N - A? Actually r = N - kA < A because kA > N - A? Let's derive: Since k = floor(N/A) ≥ 2, we have kA ≤ N < (k+1)A => N - kA < A. So r < A. Also, since A ≤ N/2, we have r < A ≤ N/2. So r < N/2. For even N, N/2 is integer, so r ≤ N/2 - 1? Actually r < N/2, so max possible r in this case is at most N/2 - 1 (since r integer). For odd N, N/2 is not integer, but r ≤ floor(N/2) - 1? Because r is integer and r < N/2 => r ≤ floor(N/2) since floor(N/2) < N/2 for odd N? Wait, for odd N, N/2 = (N-1)/2 + 0.5, so floor(N/2) = (N-1)/2. Condition r < N/2 means r ≤ floor(N/2) because floor(N/2) = (N-1)/2 < N/2. So r ≤ floor(N/2). But can r actually equal floor(N/2)? For odd N, say N=9, floor(N/2)=4. r < 4.5 => r ≤ 4. So r can be 4? But r is integer less than 4.5, so it could be 4. However, we also have r < A and A ≤ floor(N/2)=4. If A ≤ 4, then r < A ≤ 4. So r could be at most A-1 ≤ 3 if A=4? Actually if A=4, r < 4 => r ≤ 3. If A=3, r ≤ 2. So to get r=4, we need A > 4 (since r < A). But A ≤ floor(N/2)=4, so no. So in this case, r ≤ A-1 ≤ floor(N/2)-1 = 3. So indeed r ≤ floor(N/2)-1 for odd N. Thus maximum r in case 2 is at most floor(N/2)-1 for odd N, and ≤ N/2 -1 for even N.
Now compare to maximum r from case 1: For even N, r_max_case1 = N/2 -1. For odd N, r_max_case1 = ceil(N/2)-1 = floor(N/2). So for even N, r_max_case1 = N/2 -1, which equals the upper bound of case 2, but as argued, case 2 cannot achieve this bound because to achieve r = N/2 -1, we would need an A ≤ N/2 such that r = N/2 -1, but then r < A and A ≤ N/2 implies N/2 -1 < A ≤ N/2, so A must be N/2 (since A integer). But then r = N mod (N/2) = 0, not N/2 -1. So case 2's maximum is strictly less than N/2 -1 for even N. For odd N, r_max_case1 = floor(N/2) which is strictly greater than the maximum possible in case 2 (≤ floor(N/2)-1). So indeed the global maximum is achieved only in case 1, at the smallest A > N/2, i.e., A = floor(N/2)+1. For N=2, case 1 includes A=2 (since N/2=1, floor(1)+1=2) and case 2 includes A=1. Both give r=0, so maximum is 0, and the set of A achieving max includes both. But the smallest A > N/2 is 2, which is also the largest among all A (since A=1 also works). So it's fine.
Thus answer is always floor(N/2) + 1.
One more check: N=100000000 (even) -> output 50000001. The remainder would be 100000000 - 50000001 = 49999999. That's the maximum? Could there be a larger remainder with a different A? Possibly A = 50000000 yields remainder 0; A = 50000002 yields remainder 49999998; A = 50000001 yields 49999999; so that's max.
Thus solution is trivial.
But wait, the problem statement says: "If multiple package sizes will result in the same number of leftover cupcakes, print the largest such size." So for N=2, largest A among those that maximize leftover (0) is 2, which matches our answer. For other N, largest A among those that maximize leftover might be something else? Since we found the unique maximum, it's fine.
But need to be careful: Is it always unique? Let's test N=6: we found only A=4 yields remainder 2. Could A=3 yield remainder 2? 6 mod 3 =0. So no. So unique.
N=8: only A=5 yields remainder 3? Check A=6: 8 mod 6 =2; A=7:1; A=5:3; So unique.
N=9: only A=5 yields 4? Check A=4:1; A=5:4; A=6:3; So unique.
N=12: only A=7 yields 5? Check A=8:4; A=7:5; So unique.
Thus answer stands.
Therefore, for each test case, output (N // 2 + 1).
Implementation: read T, loop, read N, print N//2 + 1.
But let's also consider potential edge: N very large within int range. Python can handle.
Thus solution is simple.
But wait, is there any nuance with the phrase "makes as many packages as possible"? Means he fills packages with A cupcakes each until he can't fill another full package; the number of packages is the integer division floor(N/A). That's what we used.
Thus final answer.
But I'll double-check with more examples: N=2 -> answer 2. N=3 -> 2. N=4 -> 3. N=5 -> 3. N=6 -> 4. N=7 -> 4. N=8 -> 5. N=9 -> 5. N=10 -> 6. N=11 -> 6. N=12 -> 7. N=13 -> 7. So pattern: answer is (N+2)//2? For N=2, (2+2)//2=2; N=3: (3+2)//2=2.5 floor? Actually (3+2)//2 = 5//2=2, but we need 2? N=3 we think answer is 2, matches? Actually we got 2 from floor(N/2)+1 = 1+1=2. (N+2)//2 for N=3 gives (5)//2=2. So that's the same? floor(N/2)+1 = (N//2)+1. (N+2)//2 = ceil((N+2)/2)? Let's compute: For even N=10, N//2+1=5+1=6; (N+2)//2=12//2=6. For odd N=9, N//2+1=4+1=5; (9+2)//2=11//2=5. So indeed (N//2)+1 = (N+2)//2. But careful: For N=2, (2+2)//2=2, correct. So we can output (N+2)//2. But floor division in Python: N//2+1 works.
But note: For odd N, floor(N/2)+1 = (N-1)/2+1 = (N+1)/2. For even N, floor(N/2)+1 = N/2+1. So it's just (N+2)//2 because (N+2)//2 yields: if N even: (N+2)/2 = N/2+1; if N odd: (N+2)/2 = (N+1)/2 + 0.5? Actually odd N: N=2k+1, (2k+1+2)=2k+3, divided by 2 floor = k+1 = (N+1)/2? Wait, (2k+3)//2 = k+1 (since 2k+3 = 2(k+1)+1, floor = k+1). And floor(N/2)+1 = k+1. So yes. So both formulas same.
Thus answer is trivial.
Now we can produce code.
But wait, I recall a CodeChef problem "Packaging Cupcakes" (MUFFINS3) or something. Actually the problem is known: The answer is N//2 + 1. That's a typical easy problem. So I'm confident.
However, let's ensure that the problem constraints T up to 1000 and N up to 10^8, so reading input and output is fine.
Now produce final answer: For each test case, print floor(N/2)+1.
Edge Cases: None.
Thus we can write solution in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
T = int(next(it))
out = []
for _ in range(T):
N = int(next(it))
out.append(str(N//2 + 1))
sys.stdout.write("\n".join(out))
That's it.
But since they ask for largest such size if multiple, and we output floor(N/2)+1, it's always the largest? For N=2, it outputs 2, which is largest. For other N, unique.
Now test with sample: 2 -> 2; 5 -> 3. Yes.
Thus final answer. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
t = int(next(it))
out_lines = []
for _ in range(t):
n = int(next(it))
# optimal package size: floor(n/2) + 1
ans = n // 2 + 1
out_lines.append(str(ans))
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()