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.io.*;

public class AShovels {

  private static final String REGEX = " ";
  private static final Boolean DEBUG = false;
  private static final String FILE_NAME = "input.txt";


  public static void main(String[] args) throws IOException {
    if (DEBUG) {
      generate();
    }
    Solver solver = new Solver();
    solver.readData();
    solver.solve();
    solver.print();
  }

  private static void generate() throws IOException {
//    FileWriter writer = new FileWriter("input.txt");
//    writer.close();
  }

  private static class Data {
    int a, b;
  }

  private static class Solver {
    private StringBuilder myStringBuilder = new StringBuilder();
    int t;
    Data[] datas;

    void readData() throws IOException {
      Scanner scanner = new Scanner();
      t = scanner.nextInt();
      datas = new Data[t];
      for (int i = 0; i < t; i++) {
        Data data = new Data();
        data.a = scanner.nextInt();
        data.b = scanner.nextInt();
        datas[i] = data;
      }
      scanner.close();
    }

    void solve() {
      for (int i = 0; i < t; i++) {
        Data data = datas[i];
        if (data.a > data.b && data.a - data.b >= data.b) {
          out(data.b);
          newLine();
        } else if (data.b > data.a && data.b - data.a >= data.a) {
          out(data.a);
          newLine();
        } else {
          int abs = Math.abs(data.a - data.b);
          out(abs + (min(data.a, data.b) - abs) * 2 / 3);
          newLine();
        }
      }
    }

    void print() {
      System.out.println(myStringBuilder);
    }


    void out(Object object) {
      myStringBuilder.append(object);
    }

    void out(String string) {
      myStringBuilder.append(string);
    }

    public void out(boolean b) {
      myStringBuilder.append(b);
    }

    public void out(char c) {
      myStringBuilder.append(c);
    }

    public void out(int i) {
      myStringBuilder.append(i);
    }

    public void out(long lng) {
      myStringBuilder.append(lng);
    }

    public void out(float f) {
      myStringBuilder.append(f);
    }

    public void out(double d) {
      myStringBuilder.append(d);
    }

    public void newLine() {
      myStringBuilder.append("\n");
    }

    @SuppressWarnings("SameParameterValue")
    int[] splitInteger(String string, int n) {
      final String[] split = string.split(REGEX, n);
      int[] result = new int[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Integer.parseInt(split[i]);
      }
      return result;
    }


    @SuppressWarnings("SameParameterValue")
    long[] splitLong(String string, int n) {
      final String[] split = string.split(REGEX, n);
      long[] result = new long[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Long.parseLong(split[i]);
      }
      return result;
    }


    @SuppressWarnings("SameParameterValue")
    double[] splitDouble(String string, int n) {
      final String[] split = string.split(REGEX, n);
      double[] result = new double[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Double.parseDouble(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    String[] splitString(String string, int n) {
      return string.split(REGEX, n);
    }

    public int max(int a, int b) {
      return Math.max(a, b);
    }

    public int max(int[] arr) {
      int max = Integer.MIN_VALUE;
      for (int x : arr) {
        max = max(max, x);
      }
      return max;
    }

    public long max(long a, long b) {
      return Math.max(a, b);
    }

    public int min(int a, int b) {
      return Math.min(a, b);
    }

    public long min(long a, long b) {
      return Math.min(a, b);
    }

    public double max(double a, double b) {
      return Math.max(a, b);
    }

    public double min(double a, double b) {
      return Math.min(a, b);
    }

    private final static int MOD = 1000000009;

    int multMod(int a, int b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    int sumMod(int a, int b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    long multMod(long a, long b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    long sumMod(long a, long b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    int sum(int[] arr) {
      int sum = 0;
      for (int item : arr) {
        sum += item;
      }
      return sum;
    }

    long sum(long[] arr) {
      long sum = 0;
      for (long item : arr) {
        sum += item;
      }
      return sum;
    }

    long gcd(long a, long b) {
      while (b != 0) {
        long tmp = a % b;
        a = b;
        b = tmp;
      }
      return a;
    }

    private class Scanner {
      private int currentIndex = 0;
      private String[] objects;
      private final BufferedReader myReader;
      private Computable<Character> charComputer;
      private Computable<Double> doubleComputer;
      private Computable<Integer> intComputer;
      private Computable<Long> longComputer;

      Scanner() throws FileNotFoundException {
        InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;
        myReader = new BufferedReader(new InputStreamReader(in));
        charComputer = () -> objects[currentIndex].charAt(0);
        doubleComputer = () -> Double.parseDouble(objects[currentIndex]);
        intComputer = () -> Integer.parseInt(objects[currentIndex]);
        longComputer = () -> Long.parseLong(objects[currentIndex]);
      }

      String nextLine() throws IOException {
        objects = null;
        currentIndex = 0;
        return myReader.readLine();
      }

      int nextInt() throws IOException {
        return next(intComputer);
      }

      int[] nextIntArray(int n) throws IOException {
        int[] result = new int[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextInt();
        }
        return result;
      }

      long[] nextLongArray(int n) throws IOException {
        long[] result = new long[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextLong();
        }
        return result;
      }

      long nextLong() throws IOException {
        return next(longComputer);
      }

      double nextDouble() throws IOException {
        return next(doubleComputer);

      }

      char nextChar() throws IOException {
        return next(charComputer);
      }

      <T> T next(Computable<T> computer) throws IOException {
        T result;
        if (objects == null || currentIndex >= objects.length) {
          String s = myReader.readLine();
          objects = s.split(" ");
          currentIndex = 0;
        }
        result = computer.compute();
        currentIndex++;
        return result;
      }

      public void close() throws IOException {
        myReader.close();
      }

    }

    interface Computable<T> {
      T compute();
    }

  }

}
