#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1e3 + 10;
int n, a[N], b[N];
void swp(int x) {
  int tmp = n - x + 1;
  for (int i = 1; i < x + 1; i++) {
    swap(a[i], a[tmp + i - 1]);
  }
}
int main() {
  int _;
  cin >> _;
  while (_--) {
    cin >> n;
    for (int i = 1; i < n + 1; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i < n + 1; i++) {
      scanf("%d", &b[i]);
    }
    int now = 0;
    if (n % 2 != 0) {
      now = (n + 1) / 2;
      if (a[now] != b[now]) {
        cout << "No\n";
        continue;
      } else {
        now--;
      }
    } else {
      now = n / 2;
    }
    int f1;
    for (int i = now + 1 - 1; i >= 1; i--) {
      f1 = 0;
      for (int j = i + 1 - 1; j >= 1; j--) {
        if ((a[j] == b[i] && a[n + 1 - j] == b[n + 1 - i]) ||
            (a[n + 1 - j] == b[i] && a[j] == b[n + 1 - i])) {
          f1 = 1;
          swp(j);
          swp(i);
          break;
        }
      }
      if (f1 == 0) {
        break;
      }
    }
    if (f1)
      cout << "yes\n";
    else
      cout << "No\n";
  }
  return 0;
}
