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 inf = 1e18 + 5;
void solve1();
void solve2();
void solve3();
int main() {
  long long t = 1;
  cin >> t;
  while (t--) solve1();
  return 0;
}
void solve1() {
  long long a, b;
  cin >> a >> b;
  if (a == 0 || b == 0) {
    cout << 0 << '\n';
    return;
  }
  if (a >= 2 * b) {
    cout << a / 2 << '\n';
    return;
  }
  if (b >= 2 * a) {
    cout << b / 2 << '\n';
    return;
  }
  long long ans = 0;
  while (1) {
    if (b > a) swap(a, b);
    long long y = b / 2;
    ans += y;
    a = a - 2 * y;
    b = b - y;
    if (a <= 0 || b <= 0) break;
    if (a == 1 || b == 1) {
      ans++;
      break;
    }
  }
  cout << ans << '\n';
}
void solve2() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  if (is_sorted(a.begin(), a.end())) {
    cout << "Yes\n";
    return;
  }
  long long k = 10;
  while (k--) {
    for (long long i = 0; i < n; i++) {
      for (long long j = i + 1; j < n; j++) {
        if (a[j] < a[i] && b[i] != b[j]) {
          swap(a[i], a[j]);
          swap(b[i], b[j]);
        }
      }
    }
  }
  if (is_sorted(a.begin(), a.end()))
    cout << "Yes\n";
  else
    cout << "No\n";
}
void solve3() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  map<long long, vector<long long> > mp;
  for (long long i = 0; i < n; i++) {
    mp[a[i]].push_back(i);
  }
  for (long long i = 0; i < n; i++) {
    mp[b[i]].push_back(i);
  }
  map<long long, long long> cnt;
  long long maxx1 = 0, maxx2 = 0, count = 0;
  for (auto x : mp) {
    if (x.second[0] == x.second[1]) {
      count++;
    }
  }
  maxx1 = max(maxx1, count);
  maxx2 = max(maxx2, count);
  for (auto x : mp) {
    if (x.second[0] < x.second[1])
      cnt[x.second[1] - x.second[0]]++;
    else if (x.second[0] > x.second[1])
      cnt[(n - 1) - (x.second[0] - x.second[1]) + 1]++;
  }
  for (auto x : cnt) {
    maxx1 = max(maxx1, x.second);
  }
  cnt.clear();
  for (auto x : mp) {
    if (x.second[0] > x.second[1])
      cnt[x.second[0] - x.second[1]]++;
    else if (x.second[0] < x.second[1])
      cnt[(n - 1) - (x.second[1] - x.second[0]) + 1]++;
  }
  for (auto x : cnt) {
    maxx2 = max(maxx2, x.second);
  }
  cout << max(maxx1, maxx2) << '\n';
}
