#include <bits/stdc++.h>
#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, mod = 998244353;
const ll INF = 4e18;
pll operator-(const pll &a, const pll &b) {
return {a.x - b.x, a.y - b.y};
}
ll operator^(const pll &a, const pll &b) {
return a.x * b.y - a.y * b.x;
}
ll area(const pll &a, const pll &b, const pll &c) {
return abs((b - a) ^ (c - a));
}
__int128 sq(ll x) {
return (__int128)x * x;
}
void solve() {
int n; cin >> n;
vector<int> s(n);
vector<pll> q(n);
for (int i = 0; i < n; ++i) cin >> s[i], s.emplace_back(s[i]);
for (int i = 0; i < n; ++i) {
cin >> q[i].x >> q[i].y;
q.emplace_back(q[i]);
}
vector<vector<int>> match(n * 2, vector<int>(n * 2)), match2(n * 2, vector<int>(n * 2));
for (int i = 0; i < n * 2; ++i) {
match[i][i] = match2[i][i] = i;
for (int j = i + 1; j < n * 2; ++j) {
match[i][j] = match[i][j - 1];
if (s[i] == s[j]) match[i][j] = j;
}
for (int j = i - 1; j >= 0; --j) {
match2[i][j] = match2[i][j + 1];
if (s[i] == s[j]) match2[i][j] = j;
}
}
vector<vector<ll>> f(n * 2, vector<ll>(n * 2));
ll ans = 0;
for (int len = 1; len < n; ++len) {
for (int i = 0; i + len < n * 2; ++i) {
int j = i + len;
if (s[i] != s[j]) continue;
for (int k = i + 1; k < j; ++k) {
ll t = area(q[j], q[i], q[k]);
f[i][j] = max(f[i][j], t + area(q[j], q[k], q[match[k][jj]]) + f[k][match[k][jj]]);
f[i][j] = max(f[i][j], t + area(q[i], q[match2[k][ii]], q[k]) + f[match2[k][ii]][k]);
}
ans = max(ans, f[i][j]);
}
}
cout << ans << el;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int tcase = 1;
cin >> tcase;
while (tcase--) solve();
}