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;
const long long int mod = 1e9 + 7LL;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        std::chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
template <typename T>
T Max(T a, T b) {
  return a >= b ? a : b;
}
template <typename T>
T Min(T a, T b) {
  return a <= b ? a : b;
}
bool prime(long long int x) {
  if (x == 2 or x == 3) return true;
  if (x <= 4 or x % 2 == 0 or x % 3 == 0) return false;
  for (long long int i{5}; (long long int)i * i <= x; i += 6) {
    if (x % (i + 2LL) == 0 or x % i == 0) return false;
  }
  return true;
}
long long int power(long long int x, long long int y) {
  if (y == 0) return 1;
  if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long int floor_div(const long long int& a, const long long int& b) {
  return a / b - (((a ^ b) < 0) and a % b);
}
long long int ceil_div(const long long int& a, const long long int& b) {
  return a / b + (((a ^ b) >= 0) and a % b);
}
template <typename T>
void printarray(T a[], int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << '\n';
}
template <typename T>
void printvector(std::vector<T>& v) {
  for (int i = 0; i < v.size(); i++) {
    std::cout << v[i] << ' ';
  }
  std::cout << '\n';
}
int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) {
    long long int a, b;
    scanf("%lld%lld", &a, &b);
    long long int ans = Min((a + b) / 3, Min(a, b));
    printf("%lld\n", ans);
  }
}
