---
category_name: school
problem_code: SUMTRIAN
problem_name: 'Sums in a Triangle'
languages_supported:
- ADA
- ASM
- BASH
- BF
- C
- 'C99 strict'
- CAML
- CLOJ
- CLPS
- 'CPP 4.3.2'
- 'CPP 4.9.2'
- CPP14
- CS2
- D
- ERL
- FORT
- FS
- GO
- HASK
- ICK
- ICON
- JAVA
- JS
- 'LISP clisp'
- 'LISP sbcl'
- LUA
- NEM
- NICE
- NODEJS
- 'PAS fpc'
- 'PAS gpc'
- PERL
- PHP
- PIKE
- PRLG
- PYPY
- PYTH
- 'PYTH 3.4'
- RUBY
- SCALA
- 'SCM chicken'
- 'SCM guile'
- 'SCM qobi'
- ST
- TCL
- TEXT
- WSPC
max_timelimit: '3'
source_sizelimit: '5000'
problem_author: admin
problem_tester: null
date_added: 1-12-2008
tags:
- admin
time:
view_start_date: 1235621211
submit_start_date: 1235621211
visible_start_date: 1235621211
end_date: 1735669800
current: 1492507641
layout: problem
---
All submissions for this problem are available.Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear in the second line, three in the third line, etc. Develop a program which will compute the largest of the sums of numbers that appear on the paths starting from the top towards the base, so that:
- on each path the next number is located on the row below, more precisely either directly below or below and one place to the right;
- the number of rows is strictly positive, but less than 100
- all numbers are positive integers between O and 99.
### Input
In the first line integer n - the number of test cases (equal to about 1000). Then n test cases follow. Each test case starts with the number of lines which is followed by their content.
### Output
For each test case write the determined value in a separate line.
### Example
<pre>
<b>Input:</b>
2
3
1
2 1
1 2 3
4
1
1 2
4 1 2
2 3 1 1
<b>Output:</b>
5
9
</pre>
**Warning: large Input/Output data, be careful with certain languages**