# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 100010 ;
char s[ N] ;
int rk[ N] , sa[ N] , cnt[ N] , height[ N] ;
int x[ N] , y[ N] ;
int n, m;
void rsort ( )
{ for ( int i= 1 ; i<= m; i++ ) cnt[ i] = 0 ; for ( int i= 1 ; i<= n; i++ ) cnt[ x[ i] ] ++ ; for ( int i= 1 ; i<= m; i++ ) cnt[ i] += cnt[ i- 1 ] ; for ( int i= n; i; i-- ) sa[ cnt[ x[ y[ i] ] ] -- ] = y[ i] ;
}
void SA ( )
{ n= strlen ( s+ 1 ) ; m= 300 ; for ( int i= 1 ; i<= n; i++ ) x[ i] = s[ i] , y[ i] = i; rsort ( ) ; for ( int k= 1 ; k<= n; k<<= 1 ) { int p= 0 ; for ( int i= n- k+ 1 ; i<= n; i++ ) y[ ++ p] = i; for ( int i= 1 ; i<= n; i++ ) if ( sa[ i] > k) y[ ++ p] = sa[ i] - k; rsort ( ) ; swap ( x, y) ; x[ sa[ 1 ] ] = 1 , p= 1 ; for ( int i= 2 ; i<= n; i++ ) x[ sa[ i] ] = ( y[ sa[ i] ] == y[ sa[ i- 1 ] ] && y[ sa[ i] + k] == y[ sa[ i- 1 ] + k] ? p: ++ p) ; if ( p== n) break ; m= p; } for ( int i= 1 ; i<= n; i++ ) rk[ sa[ i] ] = i; for ( int i= 1 , j= 0 ; i<= n; i++ ) { if ( j) -- j; while ( s[ i+ j] == s[ sa[ rk[ i] - 1 ] + j] ) j++ ; height[ rk[ i] ] = j; }
}
int v[ 200 ] ; ll K;
int sum[ N] ;
bool check ( int x)
{ ll cnt= 0 ; for ( int i= 1 ; i<= n; i++ ) { int r= upper_bound ( sum+ sa[ i] , sum+ n+ 1 , sum[ sa[ i] - 1 ] + x) - sum; cnt+= max ( 0 , r- sa[ i] - height[ i] ) ; } return ( cnt>= K) ;
}
int main ( )
{ int Tc; scanf ( "%d" , & Tc) ; while ( Tc-- ) { scanf ( "%d%lld%s" , & n, & K, s+ 1 ) ; for ( int i= 0 ; i< 26 ; i++ ) scanf ( "%d" , & v[ i+ 'a' ] ) ; SA ( ) ; ll tot= 0 ; for ( int i= 1 ; i<= n; i++ ) tot+= n- sa[ i] + 1 - height[ i] ; if ( tot< K) { puts ( "-1" ) ; continue ; } int l= 100 ; for ( int i= 1 ; i<= n; i++ ) { l= min ( l, v[ s[ i] ] ) ; sum[ i] = sum[ i- 1 ] + v[ s[ i] ] ; } int r= sum[ n] ; while ( l< r) { int mid= l+ r>> 1 ; if ( check ( mid) ) r= mid; else l= mid+ 1 ; } printf ( "%d\n" , l) ; } return 0 ;
}