#CF1895A. Treasure Chest

Treasure Chest

Description

Monocarp has found a treasure map. The map represents the treasure location as an OX axis. Monocarp is at $0$, the treasure chest is at $x$, the key to the chest is at $y$.

Obviously, Monocarp wants to open the chest. He can perform the following actions:

  • go $1$ to the left or $1$ to the right (spending $1$ second);
  • pick the key or the chest up if he is in the same point as that object (spending $0$ seconds);
  • put the chest down in his current point (spending $0$ seconds);
  • open the chest if he's in the same point as the chest and has picked the key up (spending $0$ seconds).

Monocarp can carry the chest, but the chest is pretty heavy. He knows that he can carry it for at most $k$ seconds in total (putting it down and picking it back up doesn't reset his stamina).

What's the smallest time required for Monocarp to open the chest?

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of testcases.

The only line of each testcase contains three integers $x, y$ and $k$ ($1 \le x, y \le 100$; $x \neq y$; $0 \le k \le 100$) — the initial point of the chest, the point where the key is located, and the maximum time Monocarp can carry the chest for.

For each testcase, print a single integer — the smallest time required for Monocarp to open the chest.

Input

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of testcases.

The only line of each testcase contains three integers $x, y$ and $k$ ($1 \le x, y \le 100$; $x \neq y$; $0 \le k \le 100$) — the initial point of the chest, the point where the key is located, and the maximum time Monocarp can carry the chest for.

Output

For each testcase, print a single integer — the smallest time required for Monocarp to open the chest.

3
5 7 2
10 5 0
5 8 2
7
10
9

Note

In the first testcase, Monocarp can open the chest in $7$ seconds with the following sequence of moves:

  • go $5$ times to the right ($5$ seconds);
  • pick up the chest ($0$ seconds);
  • go $2$ times to the right ($2$ seconds);
  • pick up the key ($0$ seconds);
  • put the chest down ($0$ seconds);
  • open the chest ($0$ seconds).

He only carries the chest for $2$ seconds, which he has the stamina for.

In the second testcase, Monocarp can pick up the key on his way to the chest.

In the third testcase, Monocarp can't use the strategy from the first testcase because he would have to carry the chest for $3$ seconds, while he only has the stamina for $2$ seconds. Thus, he carries the chest to $7$, puts it down, moves $1$ to the right to pick up the key and returns $1$ left to open the chest.

题面翻译

题目描述

给你一个数轴,一开始你的位置为 00,箱子在 xx 处,钥匙在 yy 处,xyx\neq y。你需要通过一些操作打开宝箱。

当位置为 ii 时,你能执行以下操作:

  • 花费 11 秒,走向 i+1i+1i1i-1
  • 花费 00 秒,拿起 ii 处的钥匙或箱子,如果此处有的话;
  • 花费 00 秒,在 ii 处放下箱子;
  • 花费 00 秒,打开宝箱,如果箱子在 ii 处且你拿着钥匙的话。

另外给出限制:因为箱子很重,所以在整个过程中,扛着箱子的时间不得超过 kk 秒(放下再拿起箱子不会使其重置)。

现在给定 x,y,kx,y,k,请问你打开箱子的最短用时为多少? 每个测试点采用多组数据测试。

输入格式

第一行一个整数 t (1t100)t\space(1\le t\le 100),表示数据组数。

对于每组数据:唯一一行三个整数 x,y,k (1x,y100,xy,0k100)x,y,k\space(1\le x,y\le 100,x\neq y,0\le k\le 100),分别表示初始时箱子的位置,钥匙的位置和你扛着箱子的最大时长。

输出格式

tt 行,第 ii 行一个整数表示第 ii 组数据的答案。

说明/提示

数据范围与约定

$1\le t\le 100;\\1\le x,y\le 100,x\neq y;\\1\le k\le 100.$

样例解释

对于样例的第 11 组数据,可以通过以下一系列动作在第 77 秒打开箱子。

  • 花费 55 秒走到 55,
  • 花费 00 秒拿起箱子,
  • 花费 22 秒走到 77
  • 拿起钥匙、放下箱子并打开箱子,共花费 00 秒。

全过程共花费 77 秒,拿着箱子的时间仅有 22 秒,不超过给定的限制 k=2k=2。可以证明不存在更优解。

对于样例的第 22 组数据,你可以花费 55 秒走到 55 并捡起钥匙,再花费 55 秒走到 1010 并打开箱子。共花费 1010 秒,其中没有扛过箱子,不超过给定的限制 k=0k=0。可以证明不存在更优解。

对于样例的第 33 组数据,你无法像数据 11 那样将箱子直接搬到钥匙处,而必须:

  • 花费 55 秒走到 55 并扛起箱子;
  • 花费 22 秒走到 77
  • 此时你已经力竭,达到了限制 k=2k=2,所以必须花费 00 秒在 77 处放下箱子;
  • 花费 11 秒走到 88 并捡起钥匙;
  • 花费 11 秒再走到 77 并打开箱子。

全过程共花费 99 秒且刚好没有超过限制。可以证明不存在更优解。