#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5 + 5, M = 998244353, OO = 0x3f3f3f3f;
int t, n;
int a[N], b[N];
bool ok;
set<pair<int, int>> st;
map<pair<int, int>, int> ma;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    if (n % 2 == 1 && a[n / 2] != b[n / 2]) {
      cout << "No" << endl;
      continue;
    }
    for (int i = 0; i < n / 2; ++i) {
      st.insert({a[i], a[n - i - 1]});
      ma[{a[i], a[n - i - 1]}]++;
    }
    ok = 1;
    for (int i = 0; i < n / 2; ++i) {
      if (st.count({b[i], b[n - i - 1]})) {
        ma[{b[i], b[n - i - 1]}]--;
        if (!ma[{b[i], b[n - i - 1]}]) st.erase({b[i], b[n - i - 1]});
      } else if (st.count({b[n - i - 1], b[i]})) {
        ma[{b[n - i - 1], b[i]}]--;
        if (!ma[{b[n - i - 1], b[i]}]) st.erase({b[n - i - 1], b[i]});
      } else
        ok = 0;
    }
    if (ok)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
    st.clear();
    ma.clear();
  }
  return 0;
}
