This page is still under construction.

Parts of this page are still being built. What you see may change.

Power Tiller

Time limit3sMemory limit256 MB

Summary
Count distinct positions reachable by steps of lengths 1, 2, 4 and so on moving only right or up inside an A by B rectangle.
Level

Medium7 of 10

Topics
Bit manipulation, Dynamic programming, Math
Solved
No attempts yet

Problem

Yeondol has taken Sesun's power tiller out onto the coordinate plane. He drives badly, so he moves only by these two rules.

  1. Every move points either in the positive x direction or in the positive y direction.
  2. The nn-th move covers exactly 2n−12^{n-1} cells in the chosen direction.

The plane Yeondol drives on is the rectangle with corners (0,0)(0, 0), (A,0)(A, 0), (0,B)(0, B) and (A,B)(A, B), and the boundary belongs to the rectangle. Yeondol starts at (0,0)(0, 0) and never makes a move that would take him outside the rectangle. He may repeat moves as many times as he likes, or make none at all.

Counting the starting point and the position after each completed move, how many distinct coordinates can Yeondol visit?

Input

The first line contains the number of test cases TT (0≤T≤1000 \le T \le 100).

Each of the next TT lines contains two integers AA and BB (1≤A,B≤1081 \le A, B \le 10^8) separated by a space.

Output

For each test case, print on its own line how many distinct coordinates Yeondol can visit.

Examples3

  1. Example 1

    Input
    2
    2 3
    7 7
    
    Expected output
    6
    15
    
  2. Example 2

    Input
    0
    
    Expected output
  3. Example 3

    Input
    1
    1 1
    
    Expected output
    3