#include <bits/stdc++.h>
using i64 = long long;
#define endl '\n'
#define lg(x) ((int)log10(x))
#define log(x) ((int)log2(x))
#define PII std::pair<i64, i64>
#define abs(x) ((x) < 0 ? -(x) : (x))
#define Fast_IOS std::ios::sync_with_stdio(false), std::cin.tie(0)
#define debug(x) std::cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << '\n';
void max(int &a, int b) {
a = std::max(a, b);
}
const i64 mod = 998244353;
void solve() {
int n, m = 200;
std::cin >> n;
std::vector a(n + 1, std::vector<int>(3));
for (int i = 1; i <= n; i++) {
for (auto &x : a[i]) {
std::cin >> x;
}
}
int f[n + 1][m + 1][m + 1][3] = {0};
for (int i = 0; i < n; i++) {
for (int x = 0; x <= m; x++) {
for (int y = 0; y <= m; y++) {
for (int k = 0; k < 3; k++) {
int now = f[i][x][y][k];
if (x != m) now -= x;
if (y != m) now -= y;
max(f[i + 1][std::min(x + 1, m)][std::min(y + 1, m)][k], now + a[i + 1][k]);
max(f[i + 1][std::min(y + 1, m)][1][(k + 1) % 3], now + a[i + 1][(k + 1) % 3]);
max(f[i + 1][1][std::min(x + 1, m)][(k + 2) % 3], now + a[i + 1][(k + 2) % 3]);
// printf("%d %d %d %d: %d\n", i, x, y, k, f[i][x][y][k]);
}
}
}
}
int ans = 0;
for (int x = 0; x <= m; x++) {
for (int y = 0; y <= m; y++) {
for (auto t : f[n][x][y]) {
if (x != m) t -= x;
if (y != m) t -= y;
max(ans, t);
}
}
}
std::cout << ans << endl;
}
int main() {
Fast_IOS;
int T = 1;
std::cin >> T;
while (T--) {
solve();
}
return 0;
}