//
// main.cpp
// dp1
//
// Created by 布拉yuan on 2017/9/16.
// Copyright © 2017年 Zan. All rights reserved.
//
#include <iostream>
using namespace std;
int a[110][110];
int dp[110][110];
int max(int a, int b){
return a > b ? a : b;
}
int main(int argc, const char * argv[]) {
int caseNum;
cin >> caseNum;
while (caseNum --) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; ++i) {
dp[n][i] = a[n][i];
}
for (int i = n - 1; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j + 1]) + a[i][j];
}
}
cout << dp[1][1] << endl;
}
return 0;
}
/*
1 12 15 10 6 8 2 18 9 5 19 7 10 4 16
*/