// Arup Guha
// 1/16/2017
// Solution to 2014 NAQ Problem I: Tractor

import java.util.*;

public class tractor {

	public static void main(String[] args) {

		// Get first input.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<n; loop++) {

			// Get dimensions.
			int len = stdin.nextInt();
			int width = stdin.nextInt();

			// For (0, 0).
			int res = 1;

			// Add in results from each "level".
			for (int level=0; ((1<<(level+1)) - 1) <= len+width; level++)
				res += solve(len, width, level);

			// Output result.
			System.out.println(res);
		}

	}

	// Returns # of reachable points in len x width using precisely level+1 moves.
	public static int solve(int len, int width, int level) {

		// Length of all movements (just sum of powers of 2)
		int sum = ((1<<(level+1)) - 1);

		// Every point is in bounds...
		if ( sum <= Math.min(len, width)) return sum+1;

		// Here just calculate the intersection points with top of rectangle and bottom of rectangle.
		int start = sum - Math.min(len, width);
		int end =  Math.min(Math.max(len, width), sum);

		// Here are all the solutions.
		return end-start+1;
	}
}