#include #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int n2 = n * 2; vector a(n2); rep(i, n2) { cin >> a[i]; a[i]--; } vector x(n2); rep(i, n2) x[i] = i % n; bool ok = true; rep(i, n2) { if (x[i] != a[i]) { int l = i - 1; int r = l + n; if (l >= n) ok = false; else rep(j, r - l + 1) if (x[l + j] != a[r - j]) ok = false; i += n - 1; } } if (ok) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }