#include <bits/stdc++.h> 
using namespace std;
 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define li long int
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define F first
#define S second
#define MOD 1000000007
#define pii pair<lli,lli>
#define lli long long int
const int N=1002;

class cmp{
public:
   bool operator()(const pii &a,const pii &b){
        if(a.S!=b.S) return a.S>b.S;
        return a.F>b.F;
   }
};
void solve(){
    int n,x;
    cin>>n>>x;
    int a[n],i;
    for(i=0;i<n;i++) cin>>a[i];
    int ans=0,f=0;
    for(i=0;i<n;i++){
         if(is_sorted(a,a+n)){
            cout<<ans<<endl;
            return;
         }
         // if(i>0&&a[i]<a[i-1]){
              if(a[i]>x){
                 swap(a[i],x);
                 ans++;
              }
         //      else {
         //          f=1;
         //          break;
         //      }
         // }
    }
    if(f==0&&is_sorted(a,a+n)) cout<<ans<<endl;
    else cout<<"-1"<<endl;
}
int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
        fast();
  int t=1;
  cin>>t;
  while(t--){
    solve();
  }
  return 0;
}