Let's Run

4.3

3 votes
Easy
Problem

MANIT is organising a practice Marathon Let's Run in Sportomania. This is a non-competitive Marathon.
MANIT just provides the circular track of circumference 109+7 to the students and they can self evaluate them on the track. Track is bidirectional i.e. athelete can run in any direction.

Anurag, a enthusiastic athelete wants to evaluate himself and develope a strategy for his own evaluation.

Anurag starts his practice run at point S. He starts running at speed v . After each interval of time dt , he immediately increases his speed to n times and changes his direction. After some time T , he becomes tired and hence stop running.

Now Anurag calls his friend Ayush who was waiting for him at starting point to meet him at the same place where he stops. Anurag told his location to the Ayush. Find the minimum distance Ayush needs to travel?

Input:

The first line contains an integer, Q, denoting the number of queries.
The first and the only line of each query contain four space-separated integers: v, dt, n and T respectively as described in the statement.

Output:

For each query, find the minimum distance Ayush needs to travel in a single line.

Constraints:

1 ≤ Q ≤ 105
1 ≤ v,dt,n,T ≤ 109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In 1st query, Anurag runs at speed 1 for first 2 second in one direction. So it reaches at distance of 2 unit from starting point and then at speed 1*2 = 2 for next 2 second in another direction. So he travels 4 unit in reverse direction. So he is at a distance of 2 unit in reverse direction. Ayush needs to travel a distance of 2 in that direction to meet Anurag.

Rest queries are self explanatory.

All the participants need to register on the given link: Register Here

Editor Image

?