#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e4 + 10;
int a[MAXN], b[MAXN], c[MAXN];
int n;
void fun(int pre) {
  for (int i = 0; i < n; i++) c[i] = a[i];
  for (int i = 0; i <= pre; i++) {
    c[i] = a[n - pre - 1 + i];
    c[n - pre - 1 + i] = a[i];
  }
  for (int i = 0; i < n; i++) a[i] = c[i];
}
int main() {
  int T;
  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;
    } else {
      int retflag = 1;
      for (int i = n / 2 - 1; i >= 0 && retflag; i--) {
        if (a[i] == b[i] && a[n - i - 1] == b[n - i - 1]) continue;
        int flag = 1;
        for (int j = 0; j <= i && flag; j++) {
          if (flag && a[j] == b[i] && a[n - j - 1] == b[n - i - 1]) {
            flag = 0;
            fun(j);
            fun(i);
          }
          if (flag && a[j] == b[n - i - 1] && a[n - j - 1] == b[i]) {
            flag = 0;
            fun(j);
            fun(0);
            fun(i);
          }
        }
        if (flag) retflag = 0;
      }
      if (retflag)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
}
