logo AlgoBeat OnlineJudge
登录 注册

#215836. [JAG 2025 Summer Camp #3] Funini Adventure

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Funini Adventure is a very popular game. In this game, you can raise Funini by performing the following three actions.

  • Action 1: Climb a mountain to build stamina
  • Action 2: Participate in a programming contest
  • Action 3: Learn a new algorithm

You want to perform these actions several times, but each action has a cost. For , the cost of performing Action is defined as follows: if you have already performed Action exactly times, then the cost is .

Initially, you have performed each action 0 times. Find the minimum total cost required to perform actions in total.

输入格式

The input consists of multiple test cases.

The first line contains an integer (), representing the number of test cases.

test cases follow. Each test case is given in the following format.

For each test case, the first line contains an integer (), representing the number of actions you should perform.

The following 3 lines each contain two integers and (). The -th of these lines gives the coefficients for Action .

输出格式

For each test case, output a line containing a single integer – the minimum total cost to perform actions.

样例

样例输入 1

2
5
1 5
2 10
4 3
1000000
1000000 1000000
1000000 1000000
1000000 1000000

样例输出 1

20
166667166667000000

数据范围与提示

In the first test case, you need to perform the three actions a total of 5 times. If you perform Actions in this order, then the costs are and , for a total of . Since it can be shown that no sequence achieves a total cost less than , the answer is .