Baseball on the Mars is similar to that on the Earth, TOO. This game is played between two teams: the batting team and the fielding team. There are four bases on the ground: home base at (0,0), first base at (10,0), second base at (10,10) and third base at (0,10). They form a square called the baseball diamond. At every base, there stands a player of the fielding team. The players in the batting team bat the ball at home base one by one. Each of them bats exactly once. If a player bats the ball and the ball falls out of the ground (the x coordinate or the y coordinate of the falling place are both negative), this batting is considered failed and he will get an "Out" and leave the ground.If the ball falls inside the ground (the x coordinate and the y coordinate of the falling place are both nonnegative), this batting is considered successful. After the ball falls on the ground, the players of the batting team who are at bases will run to the next base. That is, the player at the home base will run to the first base, the player in the first base run to the second base, the player at the second base will run to the third base and the player at the third base will run back to the home base. At the same time, players of the fielding team catch the ball immediately after the ball falls on the ground and pass the ball to the other players of the fielding team at one of these bases. We assume that passing a ball has the speed of 5 and the players of the batting team have a running speed of 2.If a player of the fielding team at a base gets the ball absolutely BEFORE (not including at the same time) a player of the batting team whose destination is this particular base arrived, this player of the batting team will be "killed" -- get an "Out" and leave the ground. The players of the fielding team can keep passing the ball form base to base and kill many players of the batting team.The score is calculated as following. After the batting, there may be several players of batting team at some bases. If there is a player at the first base, he will get K1 points. If there is a player at the second base, he will get K2 points. If there is a player at the third base, he will get K3 points. If there is a player at the home base, he will get K4 points. And of course, after the batting, the player of batting team at the home base (if there is someone) will leave the ground, while other players remain on their position, waiting for next batting.The player of the fielding team are all clever enough, so they will use the strategy to make the batting team get as less score as possible in a bat. It is guaranteed that their best strategy is UNIQUE.
There are several cases in the input file, end by 0. For each case, The first line is an integer N (N<=1000), the number of batting team players. The second line contains 4 integers K1, K2, K3 and K4. Then N lines followed, each line contains 2 integers, the coordinate of the ball's falling place after each player of batting team bats the ball.
For each case, the output contains N lines: the score earned by the fielding team after each player of batting team bats the ball (Even a failed bat can get some score). There is a blank line after each test case.