// Arup Guha
// 4/8/2017
// Solution to 2017 Code Jam Qualification Problem C: Bathroom Stalls

import java.util.*;

public class c_large {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process all cases.
		for (int loop=1; loop<=numCases; loop++) {
			long n = stdin.nextLong();
			long k = stdin.nextLong();
			long[] res = solve(n, k);
			System.out.println("Case #"+loop+": "+res[0]+" "+res[1]);
		}
	}

	public static long[] solve(long n, long k) {

		// Initial split is in half.
		long[] res = new long[2];
		n--;
		res[0] = n - n/2;
		res[1] = n/2;
		if (k == 1) return res;

		// The key to the tree map is the length of an empty streak of stalls. The value is how many of those streaks there are.
		// This map will never have more than 2 items in it.
		TreeMap<Long,Long> map = new TreeMap<Long,Long>();
		map.put(res[0], 1L);
		if (res[1] != res[0])map.put(res[1], 1L);
		else map.put(res[0], 2L);

		// Place this person in a stall.
		k--;
		
		//i doubles since we go down levels of splitting...2 streaks, then 4 then 8 and so forth.
		// Stop before the last "iteration" of doubling.
		for (long i=2; k>i; i = (i<<1)) {

		
			TreeMap<Long,Long> tmp = new TreeMap<Long,Long>();
			for (long x : map.keySet()) {
				
				// We are splitting an odd streak into two separate streaks of the same size like 13 -> 6 me 6.
				if (x%2 == 1) {
					long start = tmp.containsKey(x/2) ? tmp.get(x/2) : 0;
					tmp.put(x/2, start+2*map.get(x));
				}
				
				// We are splitting an even string into two separate streaks of different length like 16 -> 7 me 8.
				else {
					long start = tmp.containsKey(x/2) ? tmp.get(x/2) : 0;
					tmp.put(x/2, start+map.get(x));
					start = tmp.containsKey(x/2-1) ? tmp.get(x/2-1) : 0;
					tmp.put(x/2-1, start+map.get(x));
				}
			}

			// tmp is our updated map and subtract out i people who need to find stalls.
			map = tmp;
			k -= i;
		}

		// This is our final answer.
		long val = map.get(map.lastKey()) >= k ? map.lastKey() : map.firstKey();
		res[0] = val/2;
		res[1] = (val-1)/2;
		return res;
	}
}
