Help me in solving POSTPERI problem

My issue

whats wrong in my code

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		    int n=sc.nextInt();
		    int m=sc.nextInt();
		    int k=sc.nextInt();
		    int newmin=Integer.MAX_VALUE;
		    int p=0;
		    int min=0;
		    int ans=0;
		        for(int i=1;i<=n;i++){
		            for(int j=1;j<=m;j++){
		                 p=2*(i+j);
		                 min=Math.abs(p-k);
		                 if(min<newmin){
		                     ans=min;
		                 }
		                newmin=min;
		            }
		        }
		    System.out.println(ans);
		}

	}
}

Problem Link: Poster Perimeter Practice Coding Problem

your code will give result
let say your ans is 1 at any point
and you are assigning newmin=min
if at any point let say min is 5
so your newmin =5
if your min for some case be 2
it satisfy if(min<newmin){
ans=min;
}
and you are changing ans to 2 which should not be changed

newmin=min should be inside the if condition