C - AtCoder AAC Contest Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋くんは、文字をいくつか持っています。 高橋くんが持っている文字は A, B, C のいずれかです。 はじめ、高橋くんは An _ A 個、Bn _ B 個、Cn _ C 個持っています。

高橋くんは、A1 つ、C1 つ、さらに追加で任意の 1 つの文字の合計 3 文字を使うことで、コンテストを 1 つ開催することができます。 具体的には、A2 つ、C1 つ使うと AAC を、A, B, C1 つずつ使うと ABC を、A1 つ、C2 つ使うと ACC を開催することができます。

高橋くんは、現在持っている文字を使ってコンテストをなるべく多く開催したいです。 高橋くんが最大でいくつのコンテストを開催することができるか求めてください。

T 個のテストケースが与えられるので、それぞれについて答えてください。

制約

  • 1\le T\le2\times10 ^ 5
  • それぞれのテストケースについて、
    • 0\le n _ A\le10 ^ 9
    • 0\le n _ B\le10 ^ 9
    • 0\le n _ C\le10 ^ 9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

T
\mathrm{testcase} _ 1
\mathrm{testcase} _ 2
\vdots
\mathrm{testcase} _ T

\mathrm{testcase} _ i\ (1\le i\le T)i 番目のテストケースを表しており、次の形式で与えられる。

n _ A n _ B n _ C

出力

T 行にわたって出力せよ。 i 行目 (1\le i\le T) には、i 番目のテストケースの答えを出力せよ。


入力例 1

5
3 1 2
100 0 0
1000000 1000000 1000000
31 41 59
1000000000 10000 1

出力例 1

2
0
1000000
31
1

1 つめのテストケースでは、AAC1 回、ABC1 回の計 2 回のコンテストを開催することができます。 よって、1 行目には 2 を出力してください。

Score : 300 points

Problem Statement

Takahashi has some letters. Each letter he has is A, B, or C. Initially, he has n _ A letters A, n _ B letters B, and n _ C letters C.

He can hold one contest by using one letter A, one letter C, and additionally any one letter, for a total of three letters. Specifically, he can hold AAC by using two letters A and one letter C, ABC by using one letter each of A, B, and C, and ACC by using one letter A and two letters C.

He wants to hold as many contests as possible using the letters he currently has. Find the maximum number of contests he can hold.

T test cases are given, so report the answer for each of them.

Constraints

  • 1\le T\le2\times10 ^ 5
  • For each test case,
    • 0\le n _ A\le10 ^ 9
    • 0\le n _ B\le10 ^ 9
    • 0\le n _ C\le10 ^ 9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

T
\mathrm{testcase} _ 1
\mathrm{testcase} _ 2
\vdots
\mathrm{testcase} _ T

\mathrm{testcase} _ i\ (1\le i\le T) represents the i-th test case and is given in the following format:

n _ A n _ B n _ C

Output

Output over T lines. On the i-th line (1\le i\le T), output the answer to the i-th test case.


Sample Input 1

5
3 1 2
100 0 0
1000000 1000000 1000000
31 41 59
1000000000 10000 1

Sample Output 1

2
0
1000000
31
1

In the first test case, he can hold AAC once and ABC once, for a total of two contests. Therefore, output 2 on the first line.