public static String convert_base(String s, int b1, int b2) {
        boolean neg = s.startsWith("-");
        int x = 0;
        for (int i = (neg ? 1 : 0); i < s.length(); ++i) {
            x *= b1;
            x += Character.isDigit(s.charAt(i)) ? s.charAt(i) - '0' : s.charAt(i) - 'A' + 10;
        }

        StringBuilder ans = new StringBuilder();
        while (x != 0) {
            int r = x % b2;
            ans.append((char)(r >= 10 ? 'A' + r - 10 : '0' + r));
            x /= b2;
        }

        if (ans.length() == 0) {
            ans.append('0');
        }
        if (neg) {
            ans.append('-');
        }
        ans.reverse();
        return ans.toString();
    }