I just used a double to avoid rounding errors. Then rounded at the end. Pretty easy.
import java.io.PrintWriter;
import java.util.Scanner;
/**
*
* @author Sanchit M. Bhatnagar
* @see http://uhunt.felix-halim.net/id/74004
*
*/
public class P11547 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = sc.nextInt();
while (T > 0) {
double N = sc.nextDouble();
double ans = (((N * 567.) / 9. + 7492) * 235. / 47.) - 498;
ans /= 10;
ans = Math.abs((long) ans);
out.println((long) ans % 10);
T--;
}
out.close();
sc.close();
}
}