using namespace std;
#include <iostream>
#include <utility>
#include <algorithm>
#define pii pair<int,int>

void Swap (pii &a,pii &b){
    pii t = a;
    a = b;
    b = t;
}

pii x,seq[510],sorted[510];

bool isSorted(int n){
    seq[0].first = -1;
    for (int i=1;i<=n;++i){
        if (seq[i-1].first > seq[i].first){
            return false;
        }
    }
    return true;
}

int main(){
    ios_base::sync_with_stdio(false),cin.tie(0);
    int t;

    cin >> t;
    while (t--){
        int n;

        cin >> n >> x.first;
        sorted[n+1] = {x.first,n+1};
        for (int i=1;i<=n;++i){
            cin >> seq[i].first;
            sorted[i].first = seq[i].first;
            sorted[i].second = i;
        }

        sort (sorted+1,sorted+2+n,[](pii a,pii b){
            return (a.first == b.first ? a.second < b.second : a.first < b.first);
        });

        for (int i=1;i<=n+1;++i){
            seq[sorted[i].second].second = i;
        }
        x.second = seq[n+1].second;

        if (x.second == n+1){
            cout << (isSorted(n) ? 0 : -1) << '\n';
            continue;
        }

        int cnt = 0;
        while (x.second != n+1 && !isSorted(n)){
            if (seq[x.second].first < x.first){
                cnt = -1;
                break;
            }
            else if (seq[x.second].first == x.first){
                Swap (x,seq[x.second]);
            }
            else{
                Swap (x,seq[x.second]);
                ++cnt;
            }
        }

        cout << (isSorted(n) ? cnt : -1) << '\n';
    }

    return 0;
}