For this Question: A number P is said to be binary palindromic if the binary representation of the number P is a palindrome.
Given an integer N your task is to find the minimum number that on either adding or subtracting converts the number N to a binary palindrome.The first line of input contains a single integer T denoting the number of test cases. Each of next T lines contains a single integer each containing the value of N.

Constraints:- 
1 <= T <= 10000
0 <= N <= 10^<sup>9</sup>For each test case in a new line print the minimum integer.Sample Input:-
3
6
9
20


Sample Output:-
1
0
1

Explanation:-
6 - 1 = 7(111)
9 + 0 = 0(1001)
20+1 = 21( 10101), I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
    static TreeSet<Long> palindromes = new TreeSet<>();

    public static void main(String[] args) {
        createPalindromes();

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

        while (tests-- > 0) {
            long k = sc.nextLong();

            if (palindromes.contains(k)) {
                System.out.println(0);
                continue;
            }

            long smaller = palindromes.lower(k);
            long larger = palindromes.higher(k);
            System.out.println(Math.min(Math.abs(k - smaller), Math.abs(k - larger)));

        }

    }


    private static void createPalindromes() {
        palindromes.add(0L);
        palindromes.add(1L);
        for (Integer i = 1; i < 30000; i++) {
            String binary = Integer.toBinaryString(i);
            String binaryPalindrome1 = binary + reverse(binary);
            String binaryPalindrome2 = binary + "0" + reverse(binary);
            String binaryPalindrome3 = binary + "1" + reverse(binary);
            palindromes.add(toLongValue(binaryPalindrome1));
            palindromes.add(toLongValue(binaryPalindrome2));
            palindromes.add(toLongValue(binaryPalindrome3));
        }
    }

    private static Long toLongValue(String s) {
        Long result = 0L;
        Long base = 1L;

        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == '1') {
                result += base;
            }
            base = base * 2;
        }

        return result;
    }

    static String reverse(String input) {
        StringBuilder input1 = new StringBuilder(input);
        input1.reverse();
        return input1.toString();
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?