Help me in solving MD_RIEV problem

My issue

while running it is giving the correct output with time of 0.09sec but while submitting it is showing tle

My code

/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int temp,r=0,c=0,digi=0,even=0,odd=0,i,n=1;
		int t = sc.nextInt();
		while(t>0)
		{
		    t--;
		int num = sc.nextInt();
		for(i=1;i<=num;)
		{
		    for(int j=1;j<=n;j++)
		    {
		        if(n%j==0)
		        c++;
		    }
		    temp=n;
		    while(temp>0)
		    {
		        r=r*10+temp%10;
		        temp=temp/10;
		    }
		    if(r==n&&c==2)
		    {
		        //System.out.print(n+",");
		        i++;
		        temp=n;
		        while(temp>0)
		        {
		            temp=temp/10;
		            digi++;
		        }
		        if(digi%2==0)
		        even++;
		        else
		        odd++;
		    }
		    digi=0;
		    c=0;
		    r=0;
		    n++;
		}
		System.out.println(even+" "+odd);
		even=0;
        odd=0;
        n=1;
	    }
	}
}

Problem Link: Palindromic Prime Numbers Practice Coding Problem - CodeChef

@chef_kk_05
to remove the tle just precompute the prime palindromic numbers till 10^5 before the test case loop and store it in some data structure .
and then use that ds inside test case loop.