#include "testlib.h"
#include <bits/stdc++.h>
 
using namespace std;

const int T = 1e4;
const int MAX_N = 2e5;
const int MAX_Q = 2e5;
 
int32_t main(int argc, char* argv[]) {
    registerValidation(argc, argv);
    int testCaseCount = inf.readInt(1, T, "t");
    inf.readEoln();
    int sum_n = 0, sum_q = 0;
    for (int testCase = 1; testCase <= testCaseCount; testCase++) {
        setTestCase(testCase);
        int n = inf.readInt(1, MAX_N, "n");
        inf.readSpace();
        int q = inf.readInt(1, MAX_Q, "q");
        inf.readEoln();
        sum_n += n;
        sum_q += q;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
          a[i] = inf.readInt(1, n, "a_" + to_string(i + 1));
          if (i == n - 1) inf.readEoln(); else inf.readSpace();
        }
        sort(a.begin(), a.end());
        bool is_permutation = true;
        for (int i = 0; i < n; ++i) {
          is_permutation &= a[i] == i + 1;
        }
        ensuref(is_permutation, "the array must form a permutation");
        for (int i = 0; i < q; ++i) {
          int l = inf.readInt(1, n, "l_" + to_string(i + 1));
          inf.readSpace();
          int r = inf.readInt(1, n, "r_" + to_string(i + 1));
          inf.readEoln();
          ensuref(l <= r, "l <= r must hold");
        }
    }
    ensuref(sum_n <= MAX_N, "sum of all n must not be greater than %d", MAX_N);
    ensuref(sum_q <= MAX_Q, "sum of all q must not be greater than %d", MAX_Q);
    inf.readEof();
    return 0;
}
