#include <iostream>
#include <vector>
#define let auto
#define fn auto

using namespace std;

fn fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

fn main() -> int {
    fastio();
    size_t p;
    cin >> p;
    for (let i = 0; i < p; i++) {
        size_t t;
        cin >> t;
        let arr = vector<int>();
        for (let j = 0; j < 12; j++) {
            size_t tmp;
            cin >> tmp;
            arr.push_back(tmp);
        }

        let stack = vector<int>();
        let res = 0;
        for (let elem: arr) {
            if (stack.empty()) {
                stack.push_back(elem);
            }
            let last = stack[stack.size() - 1];
            if (elem > last) {
                stack.push_back(elem);
            }
            else if (elem == last ) {
                continue;

            } else {
                while (stack[stack.size() - 1] <= elem ){
                    stack.pop_back();
                    res += 1;
                }

                let mus_last = stack[stack.size() - 1];
                
                
                if (mus_last < elem) {
                    stack.push_back(elem);
                } else if (mus_last == elem) {
                    
                }
            }
        }
    }
}