#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()

int sol(vector<int>&a, int y) {
    int lst = -1, st = 0, p = -1, st_back = -1, myp;
    for(int j = 0; j <= y; j++) {
        if(a[j] == lst) {
            st++;
            if (st == 1) {
                st_back = j + 1;

            }
            if (p == -1) p = j;
        }
    }
}

struct sgt_bottom {
    int n;
    vector<int> t;
    sgt_bottom() = default;
    sgt_bottom(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        t.resize(2 * n, 0);
    }

    void upd(int p, int v) {
        p += n;
        t[p] = v;
        p>>=1;
        while (p) {
            t[p] = t[p<<1] + t[p<<1|1];
            p>>=1;
        }
    }

    int get(int l, int r) {
        l += n;
        r += n;
        int ans = 0;
        while (l < r) {
            if (l & 1) ans += t[l++];
            if (r & 1) ans += t[--r];
            l>>=1;
            r>>=1;
        }
        return ans;
    }

    int find_kth(int k) {
        int v = 1;
        while (v<n) {
            if (t[v<<1] >= k) {
                v = v<<1;
            } else {
                k -= t[v<<1];
                v = v << 1 | 1;
            }
        }
        return v- n;
    }
};

void solve() {
    int n,q ; cin >>n >> q;
    vector<int> a(n);
    for(auto&u:a) cin >> u;
    int c1= 0 , c2=0;
    for(int u : a) {
        c1+=(u==1); c2 += (u==2);
    }
    sgt_bottom one(n), two(n);
    for(int j = 0; j < n; j++) {
        if (a[j]==1) one.upd(j, 1);
        else two.upd(j, 1);
    }
    //  for (int i = 0; i < n; i++) {
    //     cout << one.get(i, i + 1) << ' '<<two.get(i, i + 1) << endl;;
    // }
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x; cin >>x ;
            x--;
            if(a[x] != a[x + 1]) {
                if (a[x] == 1) {
                    one.upd(x, 0); one.upd(x+1, 1);
                    two.upd(x, 1); two.upd(x + 1, 0);
                } else {
                    one.upd(x, 1); one.upd(x + 1, 0);
                    two.upd(x, 0); two.upd(x + 1, 1);
                }
                swap(a[x], a[x + 1]);
        //         for (auto u:a)cout<<u << ' ';
        //         cout<<endl;
        //         for (int i = 0; i < n; i++) {
        // cout << one.get(i, i + 1) << ' '<<two.get(i, i + 1) << endl;;
    // }
            }
        } else {
            int y; cin >> y;
            y--;
            int idx, mycnt;
            if (a[y]==1) idx=  one.get(0, y+1) - 1;
            else idx = two.get(0, y+1) - 1;
            if(a[y]==1) mycnt=c1;
            if (a[y]==2) mycnt=c2;
            // cout<< a[y] << ' ' << idx << ' ' << mycnt << endl;
            // for(auto u:a) cout << u << ' ';
            // cout << endl;
            // for (int i = 0; i < n; i++) {
            //     cout << one.get(i, i + 1) << ' '<<two.get(i, i + 1) << endl;;
            // }
            if (a[y] == a[0]) {
                cout << idx + min(idx, n - mycnt) + 1 << '\n';
            } else {
                cout<< idx + min(idx+1, n-mycnt) + 1 << '\n';
            }
        }
    }
}

signed main() {
    int t = 1;
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> t;
    #else 
        cin.tie(0)->sync_with_stdio(false);
    #endif 

    while (t--) solve();

    return 0;
}