The Sun Guo in the journey to the Great Heaven, Buddha ancestors came to yield him, said: "I play a game with you, if you have the ability, a loop out of my right hand, count you win, and then do not move Sword bitter war, please the Jade Emperor to live in the West, the Heavenly Palace let you, if you can not play the palm, you also the Nether for the demon, and then a few "The sage smells the words, the dark smile:" This tathagata very good stay! My old sun went to 108,000 miles in a loop. His palm, the radius of a foot, how can not jump out? "What do you think you can do," said the sharp-sounding way: " "Buddha Way:" Do it! Do it! "The right hand, but like a lotus leaf size." That Sage received the Ruyi, Cheer Divinity, will be a longitudinal, standing in the Buddha Palm, but the voice: I go out also! "You see him all the way to the clouds, the invisible went." The holy line, suddenly see there are five sards pillars, holding a green gas. He said: "This is the end of the road." This went back, the Tathagata testified, the spirit of the temple will be I sit also. "Flip the wings of the cloud, the path back to the place, standing in the palm of the Tathagata:" I have to go, this has come. You taught the Jade Emperor to let the Heavenly Palace with me. "The Tathagata scold:" You just didn't leave my palm! "The Holy Way:" You do not know. I went to the end of the day, see five sards pillars, holding a green gas, I leave a note there, you dare to go with me to see? "The Tathagata Way:" Do not eliminate, you only look down from the bow. "The Sage opened round eyes, looked down, the original Buddha right hand middle finger wrote" Qi Sheng, to this a tour. "The Great holy Man took a startled way:" There are such things! There's such a thing! I write this word on the pillar of the brace, but how is it on his finger? Is there a foresight spell? I won't believe it! Don't believe it! Wait for me to come again! "Good holy, eager to jump out again, was the Buddha turned the palm of a flutter, the Monkey King launched the West Gate, will be five fingers into gold, wood, water, fire, earth Five mountain, called" Five Elements Mountain, "gently put him down. we assume that the palm of the Buddha is a circle (so that the Holy One will not fly out of the hand of a 108,000 of wings), the circle of the length of N, counter-clockwise as follows: 0,1,2,...,n-1, and the Holy of the distance of each flight is d. Now the Holy Place is recorded as x, and the great Sage wants to go in Y. Now you need to tell the sage how many wings to go before they reach their destination. |
There are multiple sets of test data. The first line is a positive integer t, which represents the number of groups of test data. Each set of test data consists of one row, four nonnegative integers, n (2 < n < 10^9), representing the length of the palm circle of the Tathagata, D (0 < D < n), the distance the wings can fly, x (0 <= x < n), the initial position of the great sage, y (0 <= y &l T n), where the holy Sage wants to go. Notice that the Sun Wukong's spreading clouds only turn counterclockwise. |