/* Author haleyk10198 */
/* CF handle: haleyk100198*/
/* FOR ACM-ICPC WF*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#define pb push_back

constexpr auto MOD = 1000000007LL;
constexpr auto LINF = (1LL<<60);
constexpr auto INF = 2147483647LL;
constexpr auto PI = 3.1415926535897932384626433;
constexpr auto EPS = 1E-9;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2> p){
	out << p.first << ' ' << p.second;
	return out;
}

template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2> &p){
	in >> p.first >> p.second;
	return in;
}

auto printVector = []<typename T>(ostream& out, vector<T> v){
	copy(v.begin(), v.end(), ostream_iterator<T>(out, " "));
};

/*
 * This is a simplex solver. Given m x n matrix A, m-vector b, n-vector c,
 * finds n-vector x such that
 *
 *  A x <= b (component-wise)
 *
 * maximizing
 *
 *  < x , c >
 *
 * where <x,y> is the dot product of x and y.
 *
 */
typedef long double DOUBLE;
typedef vector<DOUBLE> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

struct LPSolver {
  int m, n;
  VI B, N;
  VVD D;

  LPSolver(const VVD &A, const VD &b, const VD &c) : 
    m(b.size()), n(c.size()), N(n+1), B(m), D(m+2, VD(n+2)) {
    for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) D[i][j] = A[i][j];
    for (int i = 0; i < m; i++) { B[i] = n+i; D[i][n] = -1; D[i][n+1] = b[i]; }
    for (int j = 0; j < n; j++) { N[j] = j; D[m][j] = -c[j]; }
    N[n] = -1; D[m+1][n] = 1;
  }
	   
  void Pivot(int r, int s) {
    for (int i = 0; i < m+2; i++) if (i != r)
      for (int j = 0; j < n+2; j++) if (j != s)
	D[i][j] -= D[r][j] * D[i][s] / D[r][s];
    for (int j = 0; j < n+2; j++) if (j != s) D[r][j] /= D[r][s];
    for (int i = 0; i < m+2; i++) if (i != r) D[i][s] /= -D[r][s];
    D[r][s] = 1.0 / D[r][s];
    swap(B[r], N[s]);
  }

  bool Simplex(int phase) {
    int x = phase == 1 ? m+1 : m;
    while (true) {
      int s = -1;
      for (int j = 0; j <= n; j++) {
	if (phase == 2 && N[j] == -1) continue;
	if (s == -1 || D[x][j] < D[x][s] || D[x][j] == D[x][s] && N[j] < N[s]) s = j;
      }
      if (D[x][s] >= -EPS) return true;
      int r = -1;
      for (int i = 0; i < m; i++) {
	if (D[i][s] <= 0) continue;
	if (r == -1 || D[i][n+1] / D[i][s] < D[r][n+1] / D[r][s] ||
	    D[i][n+1] / D[i][s] == D[r][n+1] / D[r][s] && B[i] < B[r]) r = i;
      }
      if (r == -1) return false;
      Pivot(r, s);
    }
  }

  DOUBLE Solve(VD &x) {
    int r = 0;
    for (int i = 1; i < m; i++) if (D[i][n+1] < D[r][n+1]) r = i;
    if (D[r][n+1] <= -EPS) {
      Pivot(r, n);
      if (!Simplex(1) || D[m+1][n+1] < -EPS) return -numeric_limits<DOUBLE>::infinity();
      for (int i = 0; i < m; i++) if (B[i] == -1) {
	int s = -1;
	for (int j = 0; j <= n; j++) 
	  if (s == -1 || D[i][j] < D[i][s] || D[i][j] == D[i][s] && N[j] < N[s]) s = j;
	Pivot(i, s);
      }
    }
    if (!Simplex(2)) return numeric_limits<DOUBLE>::infinity();
    x = VD(n);
    for (int i = 0; i < m; i++) if (B[i] < n) x[B[i]] = D[i][n+1];
    return D[m][n+1];
  }
};

inline int sum(int x){
	return x*(x+1)/2;
}

int main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	
	int T; cin >> T;
	for(int no = 1; no <= T; no++){
		int n, m; cin >> n >> m;
		VVD A = VVD(2);
		VD B = VD(2);
		VD C;
		
		int sz = 0;
		
		B[0] = n, B[1] = m;
		for(int i = 0; i <= n; i++)
			for(int j = not i; j <= m; j++){
				if(sum(i)*(j+1) > n || sum(j)*(i+1) > m)
					break;
				A[0].pb(i);
				A[1].pb(j);
				sz++;
				C.pb(1);
			}
		
		for(int i = 0; i < sz; i++){
			A.pb(VD(sz));
			A.back()[i] = 1;
			B.pb(1);
		}
		
		LPSolver solver(A, B, C);
		VD x;
		DOUBLE value = solver.Solve(x);
		
		cout << "Case #" << no << ": ";

		cout << (int) (value+EPS) << endl;
	}

	return 0;
}
