#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;
}