#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; const int INF = 1e9; const ll LINF = 1e18; inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; } template ostream& operator << (ostream& out,const pair& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template ostream& operator << (ostream& out,const vector V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template ostream& operator << (ostream& out,const vector > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template ostream& operator << (ostream& out,const map mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ bool kadomatsu(int a,int b,int c){ if(a==b || a==c || b==c) return false; if(b>a&&b>c) return true; if(b>& a){ for(int i = 0; i < 3;i++){ if(!kadomatsu(a[i][0], a[i][1], a[i][2])) return false; if(!kadomatsu(a[0][i], a[1][i], a[2][i])) return false; } if(!kadomatsu(a[0][0], a[1][1], a[2][2])) return false; if(!kadomatsu(a[0][2], a[1][1], a[2][0])) return false; return true; } ll solve(){ ll res = 0; int L; cin >> L; vector> a(3,vector(3)); for(auto& vec:a) for(auto& in:vec) cin >> in; vector none,vs; for(int i = 0; i < 3;i++) for(int j = 0; j < 3;j++) if(!a[i][j]) none.push_back(i*3+j); else if(L-a[i][j]>0) {vs.push_back(a[i][j]); vs.push_back(L-a[i][j]);} for(int i = -1; i <= 1;i++) if(L/2+i>0) vs.push_back(L/2+i); vs.push_back(L/2); sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); vector sections; int n = (int)vs.size(); if(vs.front() > 1) sections.emplace_back(1,vs.front()-1); for(int i = 0; i < n;i++){ sections.emplace_back(vs[i],vs[i]); if(i < n-1 && vs[i]+1> T; while(T--){ cout << solve() << endl; } return 0; }