#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int a[n], b[n];
    map<pair<int, int>, int> M;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n / 2; i++) M[{a[i], a[n - 1 - i]}]++;
    for (int i = 0; i < n; i++) cin >> b[i];
    if (n % 2 == 1) {
      if (b[n / 2] != a[n / 2]) {
        cout << "No" << endl;
        continue;
      }
    }
    bool ok = 1;
    for (int i = 0; i < n / 2; i++) {
      if (M[{b[i], b[n - 1 - i]}] > 0) {
        M[{b[i], b[n - 1 - i]}]--;
      } else if (M[{b[n - 1 - i], b[i]}] > 0) {
        M[{b[n - 1 - i], b[i]}]--;
      } else {
        ok = 0;
        break;
      }
    }
    if (ok)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
