We need to understand the problem. We have T test cases. For each test case, we are given N, K, M. The cost for the i-th beer is K * i^3 rupees. So total cost = K * sum_{i=1 to N} i^3 = K * (N(N+1)/2)^2, because sum of cubes from 1 to N is (N(N+1)/2)^2.
But wait: sum_{i=1}^N i^3 = [N(N+1)/2]^2. So total cost = K * [N(N+1)/2]^2.
Navi has M rupees. So the money he needs to borrow is max(0, total cost - M). However, note that he must pay exactly that much? The problem says: "So you are required to lent him some money so that he can still be able to pay for all of the N beers." So we need to output the amount of money we need to lend him. If M >= total cost, then answer is 0? Possibly yes. But the sample: N=2, K=2, M=10. Total cost = 2 * (1^3+2^3)=2*(1+8)=18. M=10, so needed = 8. That matches sample output 8. So answer = total - M if total > M else 0.
But wait constraints: N,K up to 1000, M up to 10^6. T up to 10^5. So we need to compute quickly, using 64-bit integers. Total cost can be large: K up to 1000, N up to 1000. Sum of cubes: (1000*1001/2)^2 = (500500)^2 ≈ 2.505e11, times K=1000 gives ~2.5e14, which fits in 64-bit (max ~9e18). So we can use long long (int64_t). Use formula.
But careful: The problem statement says: "First line will contain T (No. of test cases). Each test case will contain only one line having three space separated integers : N, K and M" So we need to process T test cases. Output each answer.
But they also give sample code with only one test case. That is just template.
So we just need to compute total = K * (N*(N+1)/2)^2, answer = max(0, total - M). But careful: division by 2 may cause odd number if N*(N+1) is odd? N(N+1) is always even, so integer division is safe.
Implementation:
for each test:
read N, K, M.
long long sum_n = N;
sum_n = sum_n * (N+1) / 2; // sum 1..N = N(N+1)/2
long long total = sum_n * sum_n; // sum of cubes
total = total * K; // multiply by K
long long ans = total - M;
if (ans < 0) ans = 0;
print ans.
But check overflow: sum_n = N*(N+1)/2. N up to 1000 -> N*(N+1) = 1000*1001 = 1,001,000, half = 500,500. So sum_n fits in 32-bit. Then square: 500,500^2 = 250,500,250,000 ~2.5e11, fits in 64-bit. Multiply by K up to 1000 gives 2.5e14, still fine. So long long (signed 64-bit) safe.
But note: M up to 1e6, total is up to 2.5e14, so ans can be huge; but still within 64-bit.
Thus problem is straightforward.
But wait: Could there be tricky edge case? For N=0? But constraints N >= 1. So fine.
Given T up to 10^5, reading and computing simple arithmetic is fine.
Thus answer.
But the problem may be from some contest where they expected such formula.
But double-check: sum of cubes = (N(N+1)/2)^2 indeed.
Thus we output.
But I should also consider if they might want to compute iteratively? No.
Now think about sample input: 1 test case, N=2, K=2, M=10 -> answer 8.
Thus solution.
But wait: The problem statement: "After seeing his love with the beers, Bar's Manager has decided to make as much money as they can by asking Navi to pay K * i^3 Rupees for the i^th beer." That's what we used.
Now check if there is any hidden nuance: "Navi is at the Beer Bar where he has ordered N beers." So he orders N beers, the manager changes pricing based on cubic. So we need to compute total cost.
But what about "Navi has only M Rupees in his purse. So you are required to lent him some money so that he can still be able to pay for all of the N beers." So we lend him money. So answer = max(0, total - M).
Yes.
Given constraints, T is large, but we can compute each test case in O(1). Use fast I/O (ios_base::sync_with_stdio(false); cin.tie(0);). Because T=100k, we need fast IO.
Now we need to output answer per line.
Edge case: total may exceed 64-bit? Let's compute max: N=1000, sum = 1000*1001/2 = 500500. Square = 250500250000. Multiply by K=1000 gives 250500250000000 = 2.5050025e14. 2.5e14 < 9.22e18, so safe. So we are fine.
But wait: maybe N and K can be up to 10^3 but also maybe they are larger? The problem says 1 ≤ N, K ≤ 10^3. So yes.
Thus implement.
But I also see that there is sample code with only one test case reading. They probably want to fill in the logic.
Alright.
Now produce final answer: C++ code with fast I/O.
Let's write:
#include
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int N, K, M;
cin >> N >> K >> M;
long long sum_n = (long long)N * (N + 1) / 2;
long long total = sum_n * sum_n * K;
long long ans = total - M;
if (ans < 0) ans = 0;
cout << ans << '\n';
}
return 0;
}
But note: total = sum_n * sum_n * K could overflow if we multiply sum_n * sum_n first? Actually we computed sum_n = (N*(N+1))/2, which is integer up to 500500. Then sum_n * sum_n is up to 2.5e11, times K up to 1000 = 2.5e14, fits within 64-bit. But if we do sum_n * sum_n * K in one step, it's fine. However, careful: (N*(N+1)/2) may need to be done with long long to avoid overflow of N*(N+1) which is max 1,001,000, fits in 32-bit signed int (max ~2e9) but it's safe. But to be safe, cast to long long.
Better: long long sum_n = (long long)N * (N+1) / 2; This ensures no overflow in intermediate.
Thus correct.
Now output.
But the problem states "Sample Code" but it's just a template, not required to match exactly.
Thus final answer.
But wait: The problem might have a twist: "Navi is at the Beer Bar where he has ordered N beers. After seeing his love with the beers, Bar's Manager has decided to make as much money as they can by asking Navi to pay K * i^3 Rupees for the i^th beer." There is also possibility of rounding or something? No.
Thus solution is straightforward.
But given the high T, we need to ensure no unnecessary computations.
We can also precompute sum of cubes? But N up to 1000 only, so it's fine.
Now output.
Thus final answer.
But wait, re-reading the problem: It says "First line will contain T (No. of test cases). Each test case will contain only one line having three space separated integers : N, K and M". And sample input: 1 test case, output 8.
Our solution yields 8.
Thus correct.
But maybe there is trick: M is up to 10^6, but total may be less than M, then ans=0. So we need to output 0 in such case.
Now I'll produce final answer accordingly.
But I'll also consider if the problem might require modular arithmetic? No, it's about lending money.
Thus final.
Now as ChatGPT, we need to output code. The instruction says: "Sample Code: ..." but they give a sample code snippet. They might expect us to complete it. But we can provide full code with correct reading of T.
Thus final. ```cpp
#include
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N, K, M;
cin >> N >> K >> M;
// Sum of first N integers = N*(N+1)/2
long long sumN = (long long)N * (N + 1) / 2;
// Total cost = K * (sumN)^2
long long total = sumN * sumN * K;
long long ans = total - M;
if (ans < 0) ans = 0;
cout << ans << '\n';
}
return 0;
}