import java.io.*;
import java.util.*;

public class glade_pk_stupid {
	public static void main(String[] args) {
		new glade_pk_stupid().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int T = nextInt();
		for (int z = 0; z < T; z++) {
			int n = nextInt();
			int[] a = new int[2 * n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
				a[i + n] = a[i];
			}
			boolean gfl = false;
			for (int i = 0; i < n; i++) {
				boolean fl = false;
				boolean fl2 = true;
				if (n % 2 == 1) {
					for (int j = 0; j < n / 2; j++) {
						if (a[i + j] != a[i + n - 2 - j])
							fl2 = false;
					}
					fl = fl || fl2;
				}
				fl2 = true;
				if (n % 2 == 0) {
					for (int j = 0; j < n / 2; j++) {
						if (a[i + j] != a[i + n - j - 1])
							fl2 = false;
					}
					fl = fl || fl2;
					fl2 = true;
					for (int j = 0; j < n / 2 - 1; j++) {
						if (a[i + j] != a[i + n - 2 - j])
							fl2 = false;
					}
					fl = fl || fl2;
				}
				if (fl) {
					out.println("Yes");
					gfl = true;
					break;
				}
			}
			if (!gfl)
				out.println("No");
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("glade.in"));
			out = new PrintWriter("glade.out");
			// br = new BufferedReader(new InputStreamReader(System.in));
			// out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}