#include <bits/stdc++.h>
using namespace std;
long long int c, t, n, a[1000005], b[1000005], used[100005];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      used[i] = 0;
    }
    for (int i = 1; i <= n; i++) cin >> b[i];
    if (n % 2 == 1 && a[n / 2 + 1] != b[n / 2 + 1]) {
      cout << "NO" << endl;
      continue;
    }
    c = 1;
    long long int l, r;
    if (n % 2 == 1)
      l = n / 2, r = n / 2 + 2;
    else
      l = n / 2, r = n / 2 + 1;
    for (int j = l; j >= 1; j--) {
      long long int ok = 1;
      for (int i = 1; i <= n / 2; i++) {
        if (used[i] == 1) continue;
        if ((a[i] == b[l] && a[n - i + 1] == b[r]) ||
            (a[i] == b[r] && a[n - i + 1] == b[l])) {
          used[i] = 1;
          ok = 0;
          break;
        }
      }
      if (ok == 1) {
        c = 0;
        break;
      }
      l--;
      r++;
    }
    if (c == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
