#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 500+5;
const int inf = 1e5+5;


int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int tc;
    cin>>tc;
    while(tc--){
        int n,x;
        cin>>n>>x;
        vector<int>v(n);
        for(int &x : v) cin>>x;
        vector<int>v2 = v;
        sort(v2.begin(), v2.end());
        if(v==v2) cout<<"0\n";
        else{
            int ans = 0;
            reverse(v.begin(), v.end());
            bool mara = false;
            while(v.size()>=2){
                vector<int>tmp={x};
                while(v.size()>=2 and v.back()<=v[v.size()-2] and v.back()<=x) v.pop_back();
                while(v.size()>=2 and v.back()<=v[v.size()-2]) {
                    if(v.back()>tmp.back())
                        tmp.push_back(v.back());
                    v.pop_back();
                }
                if(v.size()>=2 and v.back()>v[v.size()-2]){
                    if(v[v.size()-2]>=tmp.back()){
                        ans += tmp.size();
                        x = v.back();
                        v.pop_back();
                    }
                    else {
                        mara = true;
                        break;
                    }
                }
            }
            if(mara) cout<<"-1\n";
            else cout<<ans<<"\n";
        }
    }

}
/*
1
10 6
8 5 6 7 8 9 10 11 12 14
*/
