Universal Cup Judging System

Universal Cup

حد الوقت: 3.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

You are given a pair of non-negative integers $W, S$.

Puffin Pataro is playing a card game by himself. There are two types of cards: card w and card s.

Initially, Pataro has $W$ cards of type w and $S$ cards of type s, and his score is $0$. He repeatedly consumes one card from the cards he has until all cards are consumed. When the $i$-th consumed card is a card s, the following effect occurs:

  • Among the $(i - 1)$-th, $(i - 2)$-th, and $(i - 3)$-th consumed cards, let $x$ be the number of cards that are card w. He gains a score of $27 \times \left(\frac{4}{3}\right)^x$.

For convenience, assume that cards consumed at positions $0$ or earlier are not card w.

Find the maximum possible total score that Pataro can obtain by consuming the cards in an appropriate order. It can be proven that the required answer is always an integer.

Solve the above problem for $T$ test cases.

Input

The input is given in the following format:

T
case1
case2
:
caseT

Each test case is given in the following format:

W S
  • $1 \le T \le 10^4$
  • $0 \le W, S \le 10^{16}$
  • All input values are integers.

Output

Print $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.

Example

Input 1

3
5 3
12 9
2026 328

Output 1

160
484
20992

Note

In the first example, it is optimal for Pataro to consume the cards in the order w, w, s, s, w, w, w, s.

  • The $3$-rd consumed card is a card s. Among the $2$-nd, $1$-st, and $0$-th consumed cards, there are $2$ cards of type w, so he gains a score of $27 \times \left(\frac{4}{3}\right)^2 = 48$.
  • The $4$-th consumed card is a card s. Among the $3$-rd, $2$-nd, and $1$-st consumed cards, there are $2$ cards of type w, so he gains a score of $27 \times \left(\frac{4}{3}\right)^2 = 48$.
  • The $8$-th consumed card is a card s. Among the $7$-th, $6$-th, and $5$-th consumed cards, there are $3$ cards of type w, so he gains a score of $27 \times \left(\frac{4}{3}\right)^3 = 64$.

Therefore, the total score Pataro can obtain is $160$. No matter how the cards are consumed, it is not possible to obtain a score greater than $160$, so the answer is $160$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1484EditorialOpen题解jianglyView
#1342EditorialOpen题解MilmonView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.