#pragma GCC optimize("O3,unroll-loops")
#include<vector>
#pragma GCC target("avx,avx2")
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

#ifdef DBG
#define $(x) x
#else
#define $(x)
#endif

#define debug(x) $(cout << #x << " = " << x << endl)

#define all(x) x.begin(), x.end()

constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1e18 + 7;

void WA() {
    cout << "THIS IS WRONG ANSWER" << endl;
    exit(0);
}

void RE() {
    exit(1);
}

void TL() {
    unsigned x = 0;
    while (true) x++;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (int qq = 0; qq < q; ++qq) {
        int t, qi;
        cin >> t >> qi;
        qi--;
        if (t == 1) {
            if (a[qi] == a[qi + 1]) continue;
            swap(a[qi], a[qi + 1]);
        } else {
            vector<bool> used(n, 0);
            int p = -1;

            vector<int> tm(n, n);
            vector<int> pr(n, n);
            for (int i = n - 1; i >= 0; --i) {
                tm[i] = pr[a[i]];
                pr[a[i]] = i;
            }

            vector<bool> b(n, 0);
            for (int i = 0; i < n; ++i) {
                if (pr[i] != n) {
                    b[pr[i]] = 1;
                }
            }

            int t = 0;
            int p1 = 0;
            int p2 = 0;

            vector<int> ps(n, -1);

            int ls = -1;
            while (t < n) {
                while (p1 < n && (b[p1] == 0 || p2 < n && a[p2] == a[p1])) {
                    p1++;
                }
                while (p2 < n && (b[p2] == 0 || p1 < n && a[p2] == a[p1])) {
                    p2++;
                }

                if (p1 > p2) {
                    swap(p1, p2);
                }

                if (p2 == n || ls != a[p1]) {
                    ps[p1] = t++;
                    b[p1] = 0;
                    if (tm[p1] != -1) {
                        b[tm[p1]] = 1;
                    }
                    ls = a[p1];
                } else {
                    ps[p2] = t++;
                    b[p2] = 0;
                    if (tm[p2] != -1) {
                        b[tm[p2]] = 1;
                    }
                    ls = a[p2];
                }  
            }



            cout << ps[qi] + 1 << '\n';
        }
    }
}

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

    int t = 1;
    $(cin >> t);
    while (t--) {
        debug("=-=-=-=-=-=-=-=");
        solve();
    }
}