#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n,q,x;
cin >> n;
vector<int> a;
for(int i=0;i<n;i++){
int x;
cin >> x;
a.push_back(x);
}
cin >> q;
vector<int> b;
for(int i=0;i<q;i++){
int x;
cin >> x;
b.push_back(x);
}
for(int i=0;i<q;i++){
int c = 0;
int qindex = b[i];
//cout << "query index = " << qindex-1 << " : " << a[qindex-1] << endl;
for(int j=0;j<=qindex-1;j++){
for(int k=qindex;k<n;k++){
cout << a[j] << " " << a[qindex-1] << " " << a[k] << endl;
if((a[j] > a[qindex-1] && a[qindex-1] > a[k]) || (a[j] < a[qindex-1] && a[qindex-1] < a[k]))
c++;
}
}
cout << c << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pewogICAgCWludCBuLHEseDsKICAgIAljaW4gPj4gbjsKICAgIAl2ZWN0b3I8aW50PiBhOwogICAgCWZvcihpbnQgaT0wO2k8bjtpKyspewogICAgCQlpbnQgeDsKICAgIAkJY2luID4+IHg7CiAgICAJCWEucHVzaF9iYWNrKHgpOwogICAgCX0KICAgIAljaW4gPj4gcTsKICAgIAl2ZWN0b3I8aW50PiBiOwogICAgCWZvcihpbnQgaT0wO2k8cTtpKyspewogICAgCQlpbnQgeDsKICAgIAkJY2luID4+IHg7CiAgICAJCWIucHVzaF9iYWNrKHgpOwogICAgCX0KICAgIAlmb3IoaW50IGk9MDtpPHE7aSsrKXsKICAgIAkJaW50IGMgPSAwOwogICAgCQlpbnQgcWluZGV4ID0gYltpXTsKICAgIAkJLy9jb3V0IDw8ICJxdWVyeSBpbmRleCA9ICIgPDwgcWluZGV4LTEgPDwgIiA6ICIgPDwgYVtxaW5kZXgtMV0gPDwgZW5kbDsKICAgIAkJZm9yKGludCBqPTA7ajw9cWluZGV4L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