#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];
        a[i]--;
    }
    vector<int> v, w;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 0) v.push_back(i);
        else w.push_back(i);
    }

    bool f = a[0] == 1;
    if (f) {
        swap(v, w);
    }

    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]);

            $(for (ll i : w) cout << i << ' '; cout  << '\n');
            $(for (ll i : v) cout << i << ' '; cout  << '\n');


            if (a[qi] == f) {
                *lower_bound(all(w), qi) = qi + 1;
                *lower_bound(all(v), qi + 1) = qi;
            } else {
                *lower_bound(all(v), qi) = qi + 1;
                *lower_bound(all(w), qi + 1) = qi;
            }
            if (qi == 0) {
                f ^= 1;
                swap(v, w);
            }
        } else {
            if (a[qi] == 0) {
                int i = lower_bound(all(v), qi) - v.begin();
                if (i >= w.size()) {
                    cout << i + w.size() + 1 << '\n';
                } else {
                    cout << 2 * i + 1 << '\n';
                }
            } else {
                int i = lower_bound(all(w), qi) - w.begin();
                if (i >= (int)v.size() + 1) {
                    cout << i + v.size() + 1 << '\n';
                } else {
                    cout << 2 * i + 2 << '\n';
                }
            }
        }
    }
}

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

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