The Legend of Freya the Frog

The Legend of Freya the Frog

Problem

Freya the Frog is traveling on the 2D coordinate plane. She is currently at point (0,0) and wants to go to point (x,y). In one move, she chooses an integer d such that 0≤d≤k and jumps d spots forward in the direction she is facing.

Initially, she is facing the positive x direction. After every move, she will alternate between facing the positive x direction and the positive y direction (i.e., she will face the positive y direction on her second move, the positive x direction on her third move, and so on).

What is the minimum amount of moves she must perform to land on point (x,y)?

Input

The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 4 ) (1≤t≤10^4) (1t104) — the number of test cases.

Each test case contains three integers x x x, y y y, and k k k ( 0 ≤ x , y ≤ 1 0 9 , 1 ≤ k ≤ 1 0 9 ) (0≤x,y≤10^9,1≤k≤10^9) (0x,y109,1k109).

Output

For each test case, output the number of jumps Freya needs to make on a new line.

Example

Input
3
9 11 3
0 10 8
1000000 100000 10
Output
8
4
199999

Note

In the first sample, one optimal set of moves is if Freya jumps in the following way: (0,0) → (2,0) → (2,2) → (3,2) → (3,5) → (6,5) → (6,8) → (9,8) → (9,11). This takes 8 jumps.

Code

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll t;
    cin>>t;

    while(t--)
    {
        ll x,y,k;
        cin>>x>>y>>k;

        ll ans=max((x+k-1)/k*2-1,(y+k-1)/k*2);
        cout<<ans<<endl;
    }
    
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值