We need to parse the problem: There's an N x N x N cube made of unit cubes (1x1x1). It's dropped in Coke and fully immersed. Then taken out. The son scraps off all the smaller cubes that got dirty, i.e., any small cube that has coke on any one of its six faces. After scraping, what is the total volume of material scrapped off? That's the sum of volumes of those unit cubes, each with volume 1, so essentially the number of unit cubes that have at least one face exposed to the coke when immersed.
But careful: When the cube is fully immersed, the entire outer surface of the large cube gets in contact with coke. That means any unit cube that is on the surface of the larger cube will have at least one face exposed to the coke (since the cube is solid, no internal cavities). However, note that the unit cubes that are interior (not on the surface) have no faces in contact with the coke, because they are completely surrounded by other unit cubes. So the number of unit cubes that get dirty equals the total number of unit cubes minus the number of interior unit cubes (if any). Since the cube is solid, interior cubes form a smaller cube of side (N-2) if N>=2. For N=1, there is no interior cube; the only cube is on the surface. So the number of dirty cubes = total cubes - interior cubes (if any). So volume = N^3 - max(0, (N-2)^3). But we must consider that if N=1, (N-2)^3 = (-1)^3 = -1, we need to treat interior as 0. So max(0, (N-2)^3) but note that if N=2, interior cube side length = 0? Actually for N=2, interior cubes: the small cubes are all on the surface? Let's think: A 2x2x2 cube: there are 8 unit cubes. Each unit cube has some faces on the exterior? Let's examine: In a 2x2x2 arrangement, each unit cube is at a corner? Actually each unit cube touches the surface? Since the large cube is 2 units on each side, every unit cube has at least one face that is part of the outer surface. For example, consider the cube at (1,1,1) (using coordinates 1..N). Its faces: x=1 is outer surface; y=1; z=1 all outer surfaces. Similarly, all cubes have at least one coordinate equal to 1 or 2, so they are on surface. There is no completely interior cube because interior would require coordinates all between 2 and N-1? For N=2, interior region would have side length N-2 = 0, so zero cubes. So interior cubes count = max(0, (N-2)^3). For N=2: (2-2)^3 = 0. So total dirty = 8 - 0 = 8. But wait, is that correct? The problem says: "A cube that had coke on any one of its six faces was considered to be dirty." When the big cube is fully immersed, the coke contacts the outer surfaces. However, note that each unit cube has 6 faces; those faces that lie on the exterior of the big cube get coke. But if a unit cube is on the exterior, does it always have at least one face with coke? Yes, because it is exposed. But also note: some cubes that are interior may still have coke on some face if the coke seeped into gaps? But problem says: "There is no hole or space between 2 smaller cubes." So the cube is solid, no gaps. So interior cubes are completely surrounded by other cubes; their faces are adjacent to other cubes, not exposed to coke. So only surface cubes are dirty.
Thus answer = number of surface cubes = N^3 - (N-2)^3, for N>=2, and for N=1, answer = 1 (since (1-2)^3 = -1, but we can treat as 0 interior). The formula N^3 - (N-2)^3 works for N>=1? Let's test: N=1: 1 - (-1)^3? Actually (1-2) = -1, (-1)^3 = -1, so N^3 - (N-2)^3 = 1 - (-1) = 2, which is wrong. So we must treat interior cubes as 0 for N<2. But N can be 1, but also N can be 0? No, N>=1. So we need to condition: if N=1, answer = 1; else answer = N^3 - (N-2)^3.
But note: N can be up to 10^9, so N^3 can be huge (10^27) which doesn't fit in 64-bit? Actually 10^9 cubed is 10^27, which is beyond 64-bit (max ~9.22e18). So we need to use big integers? But typical programming contest might have constraints that require 64-bit? Actually 10^9 cubed is 1e27, which is 90 bits. So we need 128-bit or big integers. But the problem may be from CodeChef or something? It says T up to 100, N up to 1e9. The output volume likely fits in 64-bit? Let's compute N^3 - (N-2)^3 = (N^3 - (N^3 - 6N^2 + 12N - 8)) = 6N^2 - 12N + 8. Wait, compute (N-2)^3 = N^3 - 6N^2 + 12N - 8. So N^3 - (N-2)^3 = 6N^2 - 12N + 8. For N=1: 6-12+8 = 2, but we need 1. So that formula works for N>=2? For N=2: 64 -24+8 = 24-24+8=8, correct. For N=3: 69 -36+8 =54-36+8=26, matches sample. For N=1: gives 2, but the correct answer for N=1 should be 1? Let's examine: In a 1x1x1 cube, there's one unit cube. It is completely exposed: all 6 faces have coke? Actually when immersed, the coke touches all faces of the big cube. The single small cube constitutes the whole big cube, so its faces are the outer surfaces. So it has coke on all 6 faces. Therefore it's dirty, so volume=1. So why does the formula give 2? Because interior volume (N-2)^3 for N=1 gives negative, which is nonsense. So we need to handle N=1 separately. For N>=2, the formula 6N^2 - 12N + 8 works.
But careful: For N=2, interior cubes count (N-2)^3 = 0, so total dirty = 8. Does that make sense? In a 2x2x2 cube, all 8 cubes are on the surface? Let's check: each small cube is a corner? Actually a 2x2x2 arrangement: coordinates (1,1,1), (1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), (2,2,1), (2,2,2). Each of these has at least one face on the exterior? For example, the cube at (1,1,1) has faces at x=1, y=1, z=1, all exterior. The cube at (2,2,2) has faces at x=2, y=2, z=2, all exterior. The cube at (1,2,1) has faces at x=1, y=2, z=1, all exterior. So yes, all 8 are on the surface. So dirty = 8. So formula gives 64 - 122 + 8 = 24-24+8=8, correct.
So answer for N=1 is 1, for N>=2 answer = 6N^2 - 12N + 8.
But we must check N=0? Not applicable.
Now constraints: N up to 1e9, so N^2 up to 1e18, which fits in 64-bit unsigned? 1e18 fits within 2^63-1 (~9.22e18) Actually 1e18 < 9.22e18, so it's fine. 6N^2 can be up to 6e18, still < 9.22e18? 6e18 is less than 9.22e18, yes. So 64-bit signed integer can hold up to 9.22e18. 6*(1e9)^2 = 6e18, which is within 2^63-1. Then subtract 12N (max 1.2e10) and add 8, still within range. So we can use 64-bit signed (like long long in C++). But careful: For N=10^9, N^2 = 10^18, 6N^2 = 6e18, which is less than 9.22e18. So safe. However, some languages like Python have arbitrary precision, so fine.
Thus solution: For each test case, read N. If N == 1: print 1; else: print 6NN - 12*N + 8.
But wait: is there any nuance? The cube is immersed fully, then taken out. The son scrapes off all smaller cubes that got dirty. But what about cubes that are partially dirty? It says any cube that had coke on any one of its six faces was considered dirty. So even if only one face had coke, it's dirty. So surface cubes indeed. But what about cubes that are on the surface but have some faces not exposed? That's fine; they still have at least one face exposed. So all surface cubes are included.
Now, check N=2, answer 8. The total volume is 8, so everything scrapped. That seems plausible: after scraping off all dirty cubes, nothing remains. That is the scrap volume = whole cube volume.
Now is there any scenario where interior cubes might get dirty due to coke seeping through edges? Problem says there is no hole or space, so no seepage.
Thus answer formula is correct.
But wait, the problem statement: "Chandan gave his son a cube with side N. The N X N X N cube is made up of small 1 X 1 X 1 cubes." So it's a solid cube of unit cubes. Then he dropped it in a tank of Coke, the cube got totally immersed. So all exterior surfaces are in contact with Coke. Then he takes out the cube, and his son scraps off all smaller cubes that got dirty. So as argued.
But we should double-check: sometimes there is a twist: The cubes that are on the surface but also have some faces that are not in contact with Coke? But all surface cubes have at least one face that is part of the outer surface, thus got coke. So they are dirty.
Thus answer.
Now, consider N=1: The only small cube is the whole cube. It has coke on all faces. So dirty. So scrap volume = 1.
But sample: input 1 gives output 1. Input 3 gives output 26. Our formula for N=3 gives 69 - 123 + 8 = 54 - 36 + 8 = 26. For N=1, our special case gives 1. So matches.
Thus solution is trivial.
But caution: The problem may be trick: The cube is immersed, so the coke touches all outer faces. But after taking it out, the son scrapes off dirty cubes. Could there be cubes that are not dirty but later become exposed because adjacent cubes are scrapped? No, the process is: He first scrapes off all cubes that got dirty. He doesn't scrape further after removing some. So it's only the originally dirty ones.
Thus final answer: For each test case, if N==1: print 1; else print 6NN - 12*N + 8.
But we can also unify formula using max: volume = N^3 - max(0, (N-2)^3). For N=1, (N-2)^3 = -1, so max = 0, then volume = 1 - 0 = 1. Actually careful: max(0, (N-2)^3) for N=1 yields 0 because (N-2)^3 = -1 < 0. So then N^3 - 0 = 1. So it works! For N=2: (0)^3 = 0, max=0, then 8-0=8. For N=3: (1)^3=1, max=1, then 27-1=26. So indeed we can use volume = N^3 - max(0, (N-2)^3). But we need to compute (N-2)^3 only if N>=2? Actually (N-2)^3 may be negative for N=1, so we take max with 0. But this involves computing N^3, which for N up to 1e9 is 1e27, which doesn't fit in 64-bit. So we cannot compute N^3 directly. So we must use the simplified polynomial 6N^2 - 12N + 8 for N>=2, and handle N=1 separately.
Alternatively, we can compute using 64-bit if we avoid N^3. So the polynomial is safe.
Thus implement.
Edge cases: N=0 not allowed. T up to 100.
Now let's ensure the sample output matches.
Thus solution is ready.
But wait, is there any scenario where N=0? No.
Thus answer.
I'll produce the final explanation.
Now, for the code: read T, loop, read N, if N == 1: print 1; else: compute ans = 6NN - 12*N + 8, print ans.
But note: 6NN may overflow if N is 1e9 and using 32-bit int. So use long long.
In Python, it's fine.
One more nuance: Could N be 1? Yes. Could N be 2? Yes.
Thus final.
But I'll also consider if N=1 but we use formula: 6*1 -12 +8 = 2. So wrong. So need condition.
But perhaps we can derive a unified formula that works for N=1: The number of surface cubes for an N x N x N cube: If N=1, surface cubes = 1; if N>1, it's N^3 - (N-2)^3 = 6N^2 - 12N + 8. But for N=1, 6-12+8 =2, so not equal. So we can't unify without condition.
Thus implement condition.
Now, in the problem statement they might expect the formula and handle N=1 as a special case, or they might think of the volume as N^3 - (N-2)^3 and if N=1, (N-2)^3 = -1, but volume is 1? Actually (N-2)^3 negative would subtract negative, giving +, but they likely intend (N-2)^3 for N>=2. So safe.
Thus final answer.
Now, writing solution: For each test case, read N as integer. Compute:
if N == 1: print(1)
else:
ans = 6 * N * N - 12 * N + 8
print(ans)
That's it.
But wait: Might there be any other interpretation? Could it be that after immersion, the coke only wets the outer layer, but when the cube is taken out, the coke might have seeped into the cracks between cubes? The problem says "There is no hole or space between 2 smaller cubes." So no seepage. So interior not wet.
Thus answer stands.
Now confirm with sample: Input: 2, then 1 -> output 1; then 3 -> output 26.
Thus correct.
Now, think about large N: N=10^9, ans = 6e18 - 12e9 + 8 ≈ 6e18. That fits in 64-bit signed? 6e18 < 9.22e18, so yes. In C++, long long (signed) range is –9.22e18 to 9.22e18. 6e18 is safe. But 6NN: N is int (maybe 32-bit). N*N for N=1e9 gives 1e18, which overflows 32-bit. So we need to cast to long long. Better to use long long for N in C++.
Thus final code:
#include
using namespace std;
int main() {
int t;
long long n;
cin >> t;
while(t--) {
cin >> n;
if(n == 1) cout << "1\n";
else {
long long ans = 6 * n * n - 12 * n + 8;
cout << ans << "\n";
}
}
return 0;
}
But careful: 6 * n * n - 12 * n + 8 might overflow if n is up to 10^9? n is long long, 6nn: n*n = 1e18, times 6 = 6e18, fits within 2^63-1? 2^63-1 = 9223372036854775807 ≈ 9.22e18. 6e18 < 9.22e18, so ok. But if n were 2e9, it would overflow, but constraint is 1e9. So safe.
Alternatively, we can use unsigned long long for extra safety. But signed is fine.
Now, we should also consider if N can be 0? Not.
Thus solution is done.
Now, provide answer.
But we need to output volume, which is number of unit cubes, each of volume 1, so same as count.
Thus final.
Now, I'll produce final explanation: The number of unit cubes with at least one face on the surface is total cubes minus interior cubes. For N=1, all cubes are surface (1). For N>1, interior cubes form a cube of side (N-2), so count = N^3 - (N-2)^3 = 6N^2 - 12N + 8.
Thus code as above.
Make sure to handle large N with 64-bit.
Now I'm ready to produce final answer. ```python
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out_lines = []
idx = 1
for _ in range(t):
n = int(data[idx]); idx += 1
if n == 1:
out_lines.append("1")
else:
# 6n^2 - 12n + 8 fits in 64-bit because n ≤ 10^9
ans = 6 * n * n - 12 * n + 8
out_lines.append(str(ans))
sys.stdout.write("\n".join(out_lines))
if name == "main":
main()