#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007
#define sz(c)  (int) c.size()
#define all(c) c.begin(), c.end()
#define tr(container,it) for(__typeof(container.begin()) it = container.begin();it != container.end(); it++)
#define present(s,x) s.find(x) != s.end()
#define cpresent(c,x) find(all(c),x) != c.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i=0;i<n;i++)
#define dep(i,n) for(int i=n-1;i>=0;i--)
#define repn(i,a,b) for(int i=a; i<b;i++)
#define ini(n) scanf("%d",&n)
#define ind(n,m) scanf("%d %d",&n,&m);
#define ins(n) scanf("%s",n);
#define opi(n) printf("%d",n)
#define ops(n) printf("%s",n)
#define opn printf("\n")
#define opsp printf(" ");
#define opa(n) cout<<n
 
typedef pair<int,int> pi;
typedef vector<pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi , greater<int> >minpq;
typedef priority_queue<pi,vp,greater<pi> > mpq;

pair<ll,ll>  MinRisk(vector<int>&Marked , int idx , int N  , vvi tim , vvi risk , int T , pair<ll,ll> dp[300][300] ){
	//~ trace3("inside state " , idx, T);
	//~ if(T < 0){
		//~ cout<<"current Time is less than  0  so can not be possible return INT_MAX\n" ; 
		//~ return mp(INT_MAX,INT_MAX);
	//~ }
	if(idx == N-1){
		//~ cout<<"current state is goal state thats why returnign 0 \n" ; 
		return  {0,0} ; 
	}
	if(dp[idx][T].ff != -1)
		return dp[idx][T] ; 
		
	ll cost = INT_MAX  ;
	ll  money=  INT_MAX ; 
	
	for(int i= 0  ; i<N ; i ++){
		
		if(i == idx or Marked[i] == 1 or T<tim[idx][i])
			continue;
		Marked[i] = 1;
		//~ cout<<"state ("<<idx<<", "<<T<<") is "<<endl;
		//~ cout<<"calling State ( "<<i<<","<<T-tim[idx][i]<<")"<<endl;
		 
		pair<ll,ll> calc =  MinRisk(Marked, i ,N, tim ,risk , T-tim[idx][i] , dp);
		ll tmp = risk[idx][i] + calc.ff;
		ll tmp2 = tim[idx][i] + calc.ss;
		//~ trace1(tmp);
		if(tmp <= cost){
			cost = tmp ;
			money = tmp==cost ? min(money,tmp2) : tmp2;
		}
		
		
		Marked[i] = 0 ; 
	}
	Marked[idx] = 1; 
	//~ cout<<"State ( "<<idx<<","<<T<<")"<<"returned "<<"optimal cost as "<<cost<<"and optimal time as "<<money<<endl;
	dp[idx][T] = {cost,money};
	return  {cost,money}; 
}

int main(){
	//ios_base::sync_with_stdio(false);cin.tie(NULL);
	int t;
	cin>>t;
	while(t--){
		
		int N,T;
		cin>>N>>T;
		vvi risk;
		vvi tim ; 
		//~ trace2(N,T);
		risk.resize(N,vi(N,0));
		tim.resize(N,vi(N,0));  
		vector<int>Marked(N,0);
		for(int i = 0 ; i < N ; i++){
			for(int j=0; j < N; j++){
				cin>>tim[i][j] ; 
			}
		}
		for(int i = 0 ; i < N ; i++){
			for(int j=0; j < N; j++){
				cin>>risk[i][j] ; 
			}
		}
		pair<ll,ll> dp[300][300]  ; 
		for(int i=0; i<300 ; i++){
			for(int j = 0 ; j < 300 ; j++){
				dp[i][j].ff = -1;
				dp[i][j].ss = -1;
			}
		}
		//~ cout<<"calling State ( "<<0<<","<<T<<")"<<endl;
		pair<ll,ll> ans= MinRisk(Marked,0,N,tim, risk , T , dp );
		if(ans.ff== INT_MAX)
			cout<<"-1"<<endl;
		else{
			cout<<ans.ff<<" "<<ans.ss<<endl;
		}
	}
	
}

	

	

