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.
#include <bits/stdc++.h>
using namespace std;
bool w[100002];
bool isVowel(char c) {
  if (c != 'a' && c != 'o' && c != 'u' && c != 'e' && c != 'i') {
    return false;
  } else {
    return true;
  }
}
bool isConst(char c) {
  if (c != 'a' && c != 'o' && c != 'u' && c != 'e' && c != 'i') {
    return true;
  } else {
    return false;
  }
}
bool cmp_x(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first < b.first;
}
bool cmp_y(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second) {
    return a.first < b.first;
  }
  return a.second < b.second;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.second - a.first < b.second - b.first;
}
bool isprime(int n) {
  if (n <= 3) {
    return true;
  }
  if (n % 2 == 0) {
    return false;
  }
  if (n % 3 == 0) {
    return false;
  }
  for (int i = 5; i * i <= n; i += 4) {
    if (n % i == 0) {
      return false;
    }
    if (n % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}
bool isThere(long long arr[], long long x, long long left, long long right) {
  if (left > right) {
    return false;
  }
  long long mid = (left + right) / 2;
  if (arr[mid] < x) {
    return isThere(arr, x, mid + 1, right);
  }
  if (arr[mid] > x) {
    return isThere(arr, x, left, mid - 1);
  }
  if (arr[mid] == x) {
    return true;
  }
  return false;
}
long long binarySearch(int arr[], long long x, int size) {
  long long left = 0, right = size - 1;
  while (left <= right) {
    long long mid = (left + right) / 2;
    if (arr[mid] <= x) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  return left;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    cout << min(min(a, b), (a + b) / 3) << "\n";
  }
}
