Its showing runtime error NZEC

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

import java.util.*;

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 IOException
{
// your code goes here
int n,i;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=0;i<n;i++)
{
String str=sc.nextLine();
String res =chk(str);
}
}
static String chk(String str)
{
int i,j,x=0;
String w="";
for(i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(i==0)
{
w=w+ch;
}
else
{
for(j=0;j<i;j++)
{
char ch1=str.charAt(j);
if(ch==ch1)
{
x++;
}
}
if (x==0)
{
w=w+ch;
}
x=0;
}
}
return w;
}

}