WC '02 P4 - It's Party Time

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 2002

Cow-Bot was a success! With him roaming the streets of Scarberia gathering valuable information about the monkeys, Bo Vine feels very secure, and decides to throw a party for the cows. Bo invites all the dignitaries to his shindig, including the always popular Hugh Heifer who arrives with his escorts, Bessie and Jersey. Once the party is in full gear, however, Bo realizes that there remains a flaw with Cow-Bot: He forgot to program the instructions for him to return home!

This is a cow-tastrophe! Should Cow-Bot fall into the wrong hoofs, there could potentially be a coup attempt, for he who controls Cow-Bot, is automatically anointed the leader of the cows! Bo Vine cannot allow this to happen. He summons his best warrior, and informs him of the plan: The warrior will begin at a stepping-stone units, from the party hall. Bo has already hacked into one of NASA's GPS satellites and has acquired the current location of Cow-Bot; it turns out that he is located at a stepping stone. Accordingly, Bo Vine equips the warrior with a pogo-stick that can jump a fixed distance of units. The stones are located a fixed distance of units apart. Bo has chosen such that the first stone that the warrior lands on is the stone at which Cow-Bot is located. Your task is to tell Bo Vine how far from the party hall Cow-Bot is actually located.

From the figure, we see that the Party Hall is located at one end of this one-dimensional "street". The markers represent stones, a fixed distance apart. Note that the warrior only jumps in one direction. Note also that the warrior initially starts off at a stone and keeps jumping even if he doesn't land on a stone.

Input Specification

The first line of input contains a single integer indicating the number of test cases.
Each test case consists of a single line containing , , and .

Output Specification

A single integer that is the distance Cow-Bot is from the party hall.

Sample Input

2
2 3 4
-3 2 5

Sample Output

14
7