1. JAVA, Simon Baumgartner


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
* ACM Programming Contest
* Problem: 679 Dropping Balls
* Status: Accepted
* Runtime: 1.824
* Date: 2009-06-07
* Author: Simon Baumgartner
*
*/

public class Main {

public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader in = new BufferedReader(new FileReader("input.txt"));
int nrOfTestCases = Integer.parseInt(in.readLine());

for(int i = 0; i < nrOfTestCases; i ++){
String[] tokens = in.readLine().split(" ");
int depth = Integer.parseInt(tokens[0]);
int ballNr = Integer.parseInt(tokens[1]);

String ballNrBinary = Integer.toBinaryString(ballNr - 1);
// fill with 0
if(ballNrBinary.length() < depth){
int diff = depth - ballNrBinary.length() - 1;
for (int j = 0; j < diff; j++) {
ballNrBinary = "0" + ballNrBinary;
}
}

String ballNrBinaryReversed = new StringBuilder(ballNrBinary).reverse().toString();
int slotRelative = Integer.parseInt(ballNrBinaryReversed, 2);
int slot = (int) (Math.pow(2, depth - 1) + slotRelative);
System.out.println(slot);
}
}

}