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;
long long int M = 1e9 + 7;
long long int M2 = 998244353;
long long int M3 = 1e8;
long long int MAX = 5001;
string s = "Everything correct till here!";
void show(vector<long long int> v) {
  for (long long int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void showrev(vector<long long int> v) {
  for (long long int i = 0; i < v.size(); i++)
    cout << v[v.size() - i - 1] << " ";
  cout << "\n";
}
void showarr(long long int arr[], long long int n) {
  for (long long int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "\n";
}
void showpv(vector<pair<long long int, long long int> > v) {
  for (long long int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int ans = 0;
  while (n > 0 and m > 0) {
    if (n == 1 and m == 1) break;
    long long int temp = n;
    long long int ctr;
    if (n > m) {
      n = m;
      m = temp;
    }
    if (n * 2 < m) {
      ctr = n;
    } else if (n == m) {
      ctr = (2 * n) / 3;
    } else {
      ctr = m - n;
    }
    ans += ctr;
    m -= 2 * ctr;
    n -= ctr;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1, Q = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
