#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef set<int>::iterator ssii;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
pair<int, int> crack(int n) {
int st = sqrt(n);
int fac = n / st;
while (n % st) {
st += 1;
fac = n / st;
}
return make_pair(st, fac);
}
inline ll qpow(ll a, int n) {
ll ans = 1;
for(; n; n >>= 1) {
if(n & 1) ans *= 1ll * a;
a *= a;
}
return ans;
}
template <class T>
inline bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll ksc(ll a, ll b, ll mod) {
ll ans = 0;
for(; b; b >>= 1) {
if (b & 1) ans = (ans + a) % mod;
a = (a * 2) % mod;
}
return ans;
}
ll ksm(ll a, ll b, ll mod) {
ll ans = 1 % mod;
a %= mod;
for(; b; b >>= 1) {
if (b & 1) ans = ksc(ans, a, mod);
a = ksc(a, a, mod);
}
return ans;
}
template <class T>
inline bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
bool _check(int x) {
//
return true;
}
int bsearch1(int l, int r) {
while (l < r) {
int mid = (l + r) >> 1;
if(_check(mid)) r = mid;
else l = mid + 1;
}
return l;
}
int bsearch2(int l, int r) {
while (l < r) {
int mid = (l + r + 1) >> 1;
if(_check(mid)) l = mid;
else r = mid - 1;
}
return l;
}
template<class T>
bool lexSmaller(vector<T> a, vector<T> b) {
int n = a.size(), m = b.size();
int i;
for(i = 0; i < n && i < m; i++) {
if (a[i] < b[i]) return true;
else if (b[i] < a[i]) return false;
}
return (i == n && i < m);
}
// ============================================================== //
const ll inf = 1ll<<60;
const int maxn = 20 + 10;
ll S[maxn][maxn][maxn];
int a, b, c;
inline void expand(int i, int &b0, int &b1, int &b2) {
b0 = i&1; i >>= 1;
b1 = i&1; i >>= 1;
b2 = i&1;
}
inline int sgn(int b0, int b1, int b2) {
return (b0 + b1 + b2) % 2 == 1 ? 1 : -1;
}
ll sum(int x1, int x2, int y1, int y2, int z1, int z2) {
int dx = x2-x1+1, dy = y2-y1+1, dz = z2-z1+1;
ll ans = 0;
_rep(i, 0, 7) {
int b0, b1, b2;
expand(i, b0, b1, b2);
ans -= S[x2-b0*dx][y2-b1*dy][z2-b2*dz] * sgn(b0, b1, b2);
}
return ans;
}
void prework() {
_rep(x, 1, a) _rep(y, 1, b) _rep(z, 1, c) _rep(i, 1, 7) {
int b0, b1, b2;
expand(i, b0, b1, b2);
S[x][y][z] += S[x-b0][y-b1][z-b2] * sgn(b0, b1, b2);
}
}
void solve() {
ll ans = -inf;
_rep(x1, 1, a) _rep(x2, x1, a) _rep(y1, 1, b) _rep(y2, y1, b) {
ll M = 0;
_rep(z, 1, c) {
ll s = sum(x1, x2, y1, y2, 1, z);
chmax(ans, s - M);
chmin(M, s);
}
}
printf("%lld\n", ans);
}
void init() {
memset(S, 0, sizeof(S));
}
int main() {
freopen("input.txt", "r", stdin);
int kase;
cin >> kase;
while (kase--) {
scanf("%d%d%d", &a, &b, &c);
init();
// get data
_rep(x, 1, a) _rep(y, 1, b) _rep(z, 1, c) scanf("%lld", &S[x][y][z]);
// then prework and solve
prework();
solve();
if (kase) printf("\n");
}
}
高维前缀和是否可以考虑基于FWT实现?