#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } vector< int > manacher(const string &s) { vector< int > radius(s.size()); int i = 0, j = 0; while(i < s.size()) { while(i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) { ++j; } radius[i] = j; int k = 1; while(i - k >= 0 && i + k < s.size() && k + radius[i - k] < j) { radius[i + k] = radius[i - k]; ++k; } i += k; j -= k; } return radius; } int max_length_palindrome(string s) { vector targ = manacher(s); int odd = max(targ) * 2 - 1; string t = ""; rep(i,0,(int)s.size()){ t += s[i]; t += '$'; } t.pop_back(); int even = 0; vector tmp = manacher(t); for (int i=1; i<(int)tmp.size(); i+=2){ even = max(even, tmp[i]/2*2); } return max(odd, even); } void solve(){ int n; cin >> n; ll m; cin >> m; string s; cin >> s; if (max_length_palindrome(s) >= m){ cout << 1 << endl; return; } string t1 = s; string t2 = s; t2 += s; if (max_length_palindrome(t1) >= m){ cout << 2 << endl; return; } if (max_length_palindrome(t1) == max_length_palindrome(t2)){ cout << -1 << endl; return; } ll a = - max_length_palindrome(t1) + max_length_palindrome(t2); ll b = max_length_palindrome(t1) - a; ll f = (m - b + a - 1) / a; cout << f << endl; } int main(){ int t; cin >> t; while(t--) solve(); }