#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define pcnt __builtin_popcount #define show(x) cout<<#x<<" = "< pii; typedef vector vi; typedef vector vvi; typedef vector vpii; typedef set si; typedef pair pll; typedef vector vl; typedef vector vvl; typedef vector vpll; typedef set sl; typedef __int128_t lll; typedef pair plll; typedef vector vlll; templatestring join(vector&v) {stringstream s;FOR(i,0,sz(v))s<<' '<b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;} void dout(double d){printf("%.12f\n",d);} const int iinf = 1e9; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; int t, l, A[3][3]; bool _kdmt(int a, int b, int c){ return a != c && (b > a && b > c || b < a && b < c); } bool kdmt(){ FOR(i, 0, 3){ if(! _kdmt(A[i][0], A[i][1], A[i][2])) return false; if(! _kdmt(A[0][i], A[1][i], A[2][i])) return false; } if(! _kdmt(A[0][0], A[1][1], A[2][2])) return false; if(! _kdmt(A[2][0], A[1][1], A[0][2])) return false; return true; } main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> t; int a, b; FOR(i, 0, t){ cin >> l; si s; s.insert(0); s.insert(1); s.insert(l); s.insert(l-1); s.insert(l/2); s.insert(l/2-1); s.insert(l/2+1); vpii idx; int ans = 0; FOR(j, 0, 3)FOR(k, 0, 3){ cin >> A[j][k]; if(A[j][k] == 0){ idx.pb(mp(j, k)); }else{ s.insert(A[j][k]); s.insert(A[j][k]+1); s.insert(A[j][k]-1); } } si sn; each(itr, s){ sn.insert(*itr); sn.insert(l - *itr); } s = sn; si::iterator itrr = s.begin(); each(itr, s){ itrr++; a = *itr; b = l - *itr; if(0 < a && a < l && 0 < b && b < l){ A[idx[0].fi][idx[0].se] = a; A[idx[1].fi][idx[1].se] = b; if(kdmt()) ans += *itrr - *itr; } } cout << ans << endl; } return 0; }