#include <iostream>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>


//#include <bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define LB lower_bound
#define UB upper_bound
#define all(v) v.begin(),v.end()

using pii=pair<int,int>;
using vi=vector<int>;
using vii=vector<pii>;
using ll=long long;
using pll=pair<ll,ll>;

void setIO(string s){
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

int main() {
  //setIO("standingout");

	int n;
	int x;
	int testcases;
	cin >> testcases;
	while(testcases--){
		cin >> n >> x;
		int cnt = 0;
		int arr[n];
		for(int i = 0; i < n; i++){
			cin>> arr[i];
		}

		int sortfrombackptr = n-1;
		for(int i = n-1; i>0; i--){
			if(arr[i] >= arr[i-1]){
				sortfrombackptr--;
			}
			else{break;}
		}

		if(sortfrombackptr == 0) cout << 0 << endl;
		else{
			for(int i = 0; i < n; i++){
				if(i == sortfrombackptr-1){
					if(arr[i] <= arr[i+1]){
						break;
					}
					else if(arr[i] > x){
						int temp = x;
						x = arr[i];
						arr[i] = temp;
						cnt++;
						sortfrombackptr++;;
					}
					else{
						break;
					}
				}
				else if(arr[i] > x){
					int temp = x;
					x = arr[i];
					arr[i] = temp;
					cnt++;
				}
			}
			bool tf = true;
			for(int i = 0; tf && i < n-1; i++){
				if(arr[i] > arr[i+1]) tf = false;
			}
			if(!tf) cout <<  -1 << endl;
			else cout << cnt << endl;
		}
	}
//yhing

return 0;
}
