#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
//
//Written by : bkrtoni
//ACMer , aabu - IT
//<3 <3 <3
//
// <Header>
#define null NULL
#define f(i,start,end) for(int i=(int)start;i<(int)end;i++)
#define all(v) v.begin(),v.end()
#define x first
#define y second
#define pb push_back
#define del erase
#define pf printf
#define sc scanf
#define test int t;cin>>t;while(t--)
#define see(x) getline(cin,x)
#define read(s) freopen(s,"r",stdin)
#define out(s) freopen(s,"w",stdout)
#define mp make_pair
#define skip continue
#define stop break;
#define ios ios_base::sync_with_stdio(0)
#define i1(x) sc("%d",&x)
#define i2(x,y) sc("%d%d",&x,&y);
#define i3(x,y,z) sc("%d%d%d",&x,&y,&z)
#define toUpper(x) std::transform(x.begin(), x.end(), x.begin(), std::toupper);
#define toLower(x) std::transform(x.begin(), x.end(), x.begin(), std::tolower);
typedef long long ll;
typedef vector<int> vInt;
typedef vector<string> vStr;
typedef vector<ll> vLong;
typedef vector<char> vChar;
typedef vector<bool> vBool;
typedef unsigned long long ull;
typedef long double ldb;
typedef map<string, string> dic;
typedef pair<int, int> point;
FILE *stm;
const double PI = 22.0 / 7.0;
const ll MXN = 1e5 + 1;
const ll MNN = 1e3 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
// </Header>
// <Function>
bool srt(string a, string b){ return a.size() > b.size(); } //sort string by size
int gcd(int a, int b){ if (b == 0)return a; else gcd(b, a % b); } //GCD
int lcm(int a, int b){ return (b / gcd(a, b))*a; } //LCM
// </Function>
//int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
//int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
//int dim1 = 8;
//int dim2 = 4;
//int dx[] = { -1, 1, 0, 0 };
//int dy[] = { 0, 0, 1, -1 };
int n;
int M[11][11][11];
bool vis[11][11][11];
int res(int ff,int y,int x){
if(ff<1 or x>10 or y>10 or vis[ff][y][x])return 0;
vis[ff][y][x]=1;
//pf("%d %d %d\n",ff,y,x);
return M[ff][y][x]+
res(ff-1,y,x)+
res(ff,y+1,x)+
res(ff,y,x+1);
}
int main(){
#ifndef ONLINE_JUDGE
read("Text.txt");
out("output.txt");
#define __builtin_popcount __popcnt
#endif
//read("jumping.in");
ios;
test{
memset(M,0,sizeof M);
memset(vis,0,sizeof vis);
cin>>n;
int ff,x,y,h;
f(i,0,n){
cin>>ff>>y>>x>>h;
M[ff][y][x]=h;
}
cout<<res(10,1,1)<<endl;
}
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUyAKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci8vCi8vV3JpdHRlbiBieSA6IGJrcnRvbmkKLy9BQ01lciAsIGFhYnUgLSBJVAovLzwzIDwzIDwzCi8vCgovLyA8SGVhZGVyPgojZGVmaW5lIG51bGwgTlVMTAojZGVmaW5lIGYoaSxzdGFydCxlbmQpIGZvcihpbnQgaT0oaW50KXN0YXJ0O2k8KGludCllbmQ7aSsrKQojZGVmaW5lIGFsbCh2KSB2LmJlZ2luKCksdi5lbmQoKQojZGVmaW5lIHggZmlyc3QKI2RlZmluZSB5IHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGRlbCBlcmFzZQojZGVmaW5lIHBmIHByaW50ZgojZGVmaW5lIHNjIHNjYW5mCiNkZWZpbmUgdGVzdCBpbnQgdDtjaW4+PnQ7d2hpbGUodC0tKQojZGVmaW5lIHNlZSh4KSBnZXRsaW5lKGNpbix4KQojZGVmaW5lIHJlYWQocykgZnJlb3BlbihzLCJyIixzdGRpbikKI2RlZmluZSBvdXQocykgZnJlb3BlbihzLCJ3IixzdGRvdXQpCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgc2tpcCBjb250aW51ZQojZGVmaW5lIHN0b3AgYnJlYWs7CiNkZWZpbmUgaW9zIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCkK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