// Arup Guha
// 5/19/2018
// Solution to 2018 Code Jam Round 2 Problem B Small: Graceful Chainsaw Jugglers
// Note: Key observation that I didn't make was that for each combo with 1 red chainsaw,
//       we greedily want to have 0 blue, 1 blue, 2 blue, etc. This solution tries out
//       situations where we skip some subset of what's listed above.

import java.util.*;

public class Solution {

	public static int r;
	public static int b;
	public static HashMap<Integer,Integer> memo;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=nC; loop++) {
			r = stdin.nextInt();
			b = stdin.nextInt();
			memo = new HashMap<Integer,Integer>();
			Integer res = go(r,b,1,0);
			System.out.println("Case #"+loop+": "+res);
		}
	}

	// Solves problem for r=x, b=y is left to fill, sum is current sum to do and cR is the number of
	// red chainsaws.
	public static Integer go(int x, int y, int sum, int cR) {

		// Lots of cases here - cut out at 20, no one for the small case ever has to juggle more than 20.
		if (x == 0 && y == 0) return 0;
		if (x+y == sum && x>=cR) return 1;
		if (x+y == sum && x<cR) return null;
		if (x+y > 0 && x+y < sum) return null;
		if (sum == 20) return null;

		// Speed up...
		int code = 1000000*x+10000*y + 100*sum+cR;
		if (memo.containsKey(code)) return memo.get(code);

		// This is the next state we move to. 
		int nSum = cR == sum ? sum+1 : sum;
		int nR = cR == sum ? 0 : cR+1;
		int cB = sum-cR;
		
		// We assign one juggler to cR and cB chainsaws.
		Integer takeIt = (cR <= x && cB <= y) ? go(x-cR,y-cB,nSum,nR) : null;
		Integer res = takeIt == null ? null : takeIt+1;

		// We don't assign a juggler to cR and cB chainsaws.
		Integer leaveIt = go(x,y,nSum,nR);
		if (leaveIt != null) {
			if (res == null || leaveIt > res)
				res = leaveIt;
		}

		memo.put(code, res);
		return res;
	}


}