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.
/* package codechef; // don't place package name! */

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 br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		while(t--!=0){
		  //  int a = Integer.parseInt(br.readLine());
		  //  int[] arr = new int[n];
		    String[] in = br.readLine().split(" ");
		  //  for(int i=0;i<n;i++){
		  //      arr[i] = Integer.parseInt(in[i]);
		  //  }
		  int a = Integer.parseInt(in[0]);
		  int b = Integer.parseInt(in[1]);
		  int ans = 0;
		  if(a==0 || b==0){
		      System.out.println(0);
		      continue;
		  }
		  else if(a==1 || b==1){
		      System.out.println(1);
		      continue;
		  }
		  else if(Math.max(a,b)>=Math.min(a,b)*2){
		      System.out.println(Math.min(a,b));
		      continue;
		  }else{
		      ans = Math.min(a,b)/2;
		      if(a>b){
		          a-=(ans*2);
                  b-=ans;		          
		      }else{
		          a-=ans;
		          b-=(ans*2);
		      }
		      while(a>1 && b>1){
		          //if(a==1 || b==1){
		          //    ans+=1;
		          //    break;
		          //}
		          int temp = Math.min(a,b)/2;
		          ans += temp;
		          
		        if(a>b){
		          a-=(temp*2);
                  b-=temp;		          
		        }else{
		          a-=temp;
		          b-=(temp*2);
		      }
		      }
		      if(a==1 || b==1 && a!=b){
		          ans+=1;
		      }
		  }
		  System.out.println(ans);
		}
	}
}
