403382: GYM101147 H Commandos

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Commandostime limit per test2 secondsmemory limit per test64 megabytesinputcommandos.inoutputstandard output

A commando is a soldier of an elite light infantry often specializing in amphibious landings, abseiling or parachuting. This time our Commando unit wants to free as many hostages as it could from a hotel in Byteland, This hotel contains 10 identical floors numbered from 1 to 10 each one is a suite of 10 by 10 symmetric square rooms, our unit can move from a room (F, Y, X) to the room right next to it (F, Y, X + 1) or front next to it (F, Y + 1, X) and it can also use the cooling system to move to the room underneath it (F - 1, Y, X).

Knowing that our unit parachuted successfully in room 1-1 in floor 10 with a map of hostages locations try to calculate the maximum possible hostages they could save.

Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T. Followed by the test cases, each test case contains a number N (1 ≤ N ≤ 1, 000) representing the number of lines that follows. Each line contains 4 space separated integers (1 ≤ F, Y, X, H ≤ 10) means in the floor number F room Y-X there are H hostages.

Output

For each test case, print on a single line, a single number representing the maximum possible hostages that they could save.

ExampleInput
2
3
10 5 5 1
10 5 9 5
10 9 5 9
3
1 5 5 1
5 5 9 5
5 9 5 8
Output
10
8

加入题单

上一题 下一题 算法标签: