#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t, n, x;
	cin >> t;
	while (t--) {
		cin >> n >> x;
		vector<int> a(n);
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		if (is_sorted(a.begin(), a.end())) {
			cout << 0 << endl;
		}
		else {
			for (int i = 0; i < n; i++) {
				if (a[i] > x ) {
					swap(a[i], x);
					cnt++;
				}
				if (is_sorted(a.begin(), a.end())) {
					break;
				}
			}
			if (!is_sorted(a.begin(), a.end())) {
				cout << -1 << endl;
			} else cout << cnt << endl;
		}

	}

	return 0;
}


