You are the manager of a small soccer team. After seeing the shameless behavior of your team during the match, you are mad at all of the current players. Therefore, you have made a huge decision: put these players on the substitution bench, and buy the entire starting line-up from other teams.
You have received a list of available players from your assistant manager. Each player has three properties: Position, Value, and Cost. The Position of a player is one of the four kinds: Goalkeeper, Defender, Midfielder and Forward. The Value shows the ability of the player (the higher, the better), and the Cost is the money you need to spend to buy him.
You are going to pick some players to buy from the list, in order to form the starting line-up. Several rules should be followed:
The starting line-up consists of exactly eleven players.
There should be exactly one Goalkeeper, at least three but at most five Defenders, at least two but at most five Midfielders, and at least one but at most three Forwards in the starting line-up.
There should be exactly one captain in the starting line-up.The captain must be chosen from the eleven players.
The total value of the starting line-up is the sum of the Values of picked players plus the Value of the captain. In another word, the Value of the captain is counted twice.
The total cost of the starting line-up is the sum of the Costs of picked players, which should not exceed the given cost limitation.
Now you have to give a plan to your boss before taking the actual actions. In the plan, you should report three numbers which your boss really interests in: Vt, Ct, N, where Vt is the maximum total value you can get; Ct is the minimum total cost when the total value is Vt; And N is the number of different ways to pick players when the total value is Vt and the total cost is Ct. Since your boss does not care the precise number of N if it is larger than 1,000,000,000, just report N = 1,000,000,000 when that happens.
Note that if two or more ways that pick the same eleven players and are only different in captain chosen, they should be regarded as the same.
Input
There are several test cases in the input.
The first line contains an integer T (1 <= T <= 10) -- the number of test cases.
For each case:
The first line contains an integer M (11 <= M <= 500) -- the number of players on the list.
Then follows M lines, each line contains a string P and two integers V and C (0 <= V <= 1000, 0 <= C <= 1000), separated by a single space, describing the properties of a player. P is the position of the player, which is one of the strings “Goalkeeper”, “Defender”, “Midfielder”, and “Forward”; V is the Value of the player and C is the Cost of the player.
The last line contains an integer L (0 <= L <= 1000) -- the cost limitation.
Output
For each test case, output three integers Vt, Ct and N on a single line, separated by a single space. We assure that there is at least one possible way to pick your players.
Note
In the sample, you should pick all five Defenders, four Midfielders with Value 178, 20, 64 and 109, one Forward with Value 6, and one of two Goalkeepers with Value 57. The Midfielder with Value 178 should be the captain.