Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.

Each tool can be sold for exactly one emerald. How many emeralds can Polycarp earn, if he has a sticks and b diamonds?

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only line of each test case contains two integers a and b (0 ≤ a, b ≤ 10^9) — the number of sticks and the number of diamonds, respectively.

Output

For each test case print one integer — the maximum number of emeralds Polycarp can earn.

Example

Input


4
4 4
1000000000 0
7 15
8 7


Output


2
0
7
5

Note

In the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.

In the second test case Polycarp does not have any diamonds, so he cannot craft anything.
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(buf.readLine());
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<t;i++)
		{
		    String st[]=(buf.readLine()).split(" ");
		    long a=Long.parseLong(st[0]);
		    long b=Long.parseLong(st[1]);
		    long c;
		    if(a>b)
		    {
		        c=a;
		        a=b;
		        b=c;
		    }
		    long tool1=Math.min(a,(b/2));
		    long emerald;
		    if(a==tool1)
		    emerald=tool1;
		    else
		    {
		        long rem1=a-tool1;
		        long rem2=b%2;
		        if(rem2==1 && rem1>=2)
		        emerald=tool1+1;
		        else
		         emerald=tool1;
		    }
		    
		    long tool2=Math.min(a/3,b/3);
		    long emerald2;
		    long rem3=a%3;
		    long rem4=b%3;
		    if((rem3>=1 && rem4>=2)||(rem3>=2 && rem4>=1))
		    emerald2=(2*tool2)+1;
		    else
		    emerald2=2*tool2;
		    sb.append((Math.max(emerald,emerald2))+"\n");
		}
		System.out.println(sb);
	}
}
