// Arup Guha
// 5/20/2018
// Solution to 2018 Code Jam Round 2 Problem: Graceful Chainsaw Jugglers

import java.util.*;

public class Solution {

	public static int r;
	public static int b;
	public static int[][][] memo;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();

		// memo[i][j][k] stores best answer for r=i, b=j with minimum r for each juggler = k or greater.
		memo = new int[501][501][32];
		for (int i=0; i<=500; i++)
			for (int j=0; j<=500; j++)
				Arrays.fill(memo[i][j], -1);

		// Process each case.
		for (int loop=1; loop<=nC; loop++) {
			r = stdin.nextInt();
			b = stdin.nextInt();
			int res = go(r,b,0);
			System.out.println("Case #"+loop+": "+res);
		}

	}

	// Solves problem for r=x, b=y is left to fill, sum is current sum to do.
	public static int go(int x, int y, int curR) {

		// Can't do one more.
		if (x < curR) return 0;

		// We'll never do more than 31.
		if (curR > 31) return 0;

		// We did this before.
		if (memo[x][y][curR] != -1) return memo[x][y][curR];

		int res = 0;

		// Special case, would start at 1 instead for cnt.
		if (curR == 0) {

			// cnt represents how many on this row, ie. curR red and cnt blue.
			for (int cnt=0;;cnt++) {
				if (y-cnt*(cnt+1)/2 < 0) break;
				int tmp = cnt + go(x, y-cnt*(cnt+1)/2, curR+1);
				res = Math.max(res, tmp);
			}
		}

		// Here we can start with 0.
		else {

			// No juggler has exactly curR red chainsaws.
			res = go(x,y,curR+1);

			// cnt is the last # of blue chainsaws.
			for (int cnt=0;;cnt++) {

				// Don't have enough red or blue chainsaws.
				if (x-curR*(cnt+1) < 0) break;
				if (y-cnt*(cnt+1)/2 < 0) break;

				// cnt+1 is the number of jugglers, each with curR red chainsaws.
				int tmp = cnt + 1 + go(x-curR*(cnt+1), y-cnt*(cnt+1)/2, curR+1);
				res = Math.max(res, tmp);
			}

		}

		// Store and return.
		return memo[x][y][curR] = res;
	}

	// Returns largest x such that tri(x) <= n.
	public static int maxInvTri(int n) {
		int res = 0, sum = 0;
		while (true) {
			if (sum > n) break;
			res++;
			sum += res;
		}
		return res-1;
	}
}