Greater on the right side in Java
You're doing a lot of work to parse the input. It seems like it'd be easier if you just used the Scanner class:

final Scanner sc = new Scanner(System.in);
final int numTests = sc.nextInt();

for (int i = 0; i &lt; numTests; i++) {
    final int size = sc.nextInt();
    final int[] arr = new int[size];
    final int[] result;

    for (int j = 0; j &lt; size; j++) {
        arr[j] = sc.nextInt();
    }
    result = calcNewArr(arr);
}


Your implementation runs at \$O(n^2)\$, however, this should be possible in \$O(n)\$ time if you just looked through the array right to left. If the question was asking for left to right on a reverse of the array, the problem would be pretty obvious since it's basically just iterate through and apply some simple rules:


The first element is -1
Copy the highest number seen so far into the position
If the value replaced is greater, set it as the largest number seen so far


So, I think something like this fulfills your calcNewArray:

int largest = -1;

for (int i = ans.length - 1; i &gt;= 0; i--) {
    final int value = ans[i];
    ans[i] = largest;
    largest = Math.max(largest, value);
}


Obviously, comments can improve the code and there's some stylistic things that'll make most Java devs raise their eyebrows, but it's not a big deal. One thing, in particular, however, is to consistently use the following format for array types:

int[] arr = new int[size];


As opposed to int [] arr or int []arr