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

public class glade_sp_40 implements Runnable {

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

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			br = new BufferedReader(new FileReader(FILENAME + ".in"));
			out = new PrintWriter(FILENAME + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;

	PrintWriter out;

	StringTokenizer st;

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

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

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	private static final String FILENAME = "glade";

	long pow(long a, long b) {
		long ret = 1;
		while (b > 0) {
			if ((b & 1) == 1) {
				ret *= a;
			}
			a *= a;
			b /= 2;
		}
		return ret;
	}

	public void solve() throws IOException {
		int tests = nextInt();
		myAssert((1 <= tests) && (tests <= 10), "Wrong number of tests");
		test: while (tests-- > 0) {
			int n = nextInt();
			myAssert((2 <= n) && (n <= 1000), "Wrong number of trees");
			int[] a = new int[2 * n + 1];
			for (int i = 0; i < n; i++) {
				a[i] = a[i + n] = nextInt();
				myAssert((0 <= a[i]) && (a[i] <= 1), "Wrong tree");
			}
			a[2 * n] = a[n];
			long[] hash = new long[2 * n + 1];
			hash[0] = a[0];
			for (int i = 1; i < hash.length; i++) {
				hash[i] = hash[i - 1] * 3 + a[i];
			}
			long[] hashrev = new long[2 * n + 1];
			hashrev[2 * n - 1] = a[2 * n - 1];
			for (int i = hashrev.length - 2; i >= 0; i--) {
				hashrev[i] = hashrev[i + 1] * 3 + a[i];
			}
			if (n % 2 == 0) {
				for (int i = 0; i < n / 2; i++) {
					long h1 = hash[i + n / 2] - hash[i] * pow(3, n / 2);
					long h2 = hashrev[i + n / 2 + 1] - hashrev[i + n + 1]
							* pow(3, n / 2);
					if (h1 == h2) {
						out.println("Yes");
						continue test;
					}
				}
			}
			for (int i = 0; i < n; i++) {
				long h1 = hash[i + (n - 1) / 2] - hash[i] * pow(3, (n - 1) / 2);
				long h2 = hashrev[i + (n - 1) / 2 + 2]
						- hashrev[i + (n - 1) / 2 * 2 + 2] * pow(3, (n - 1) / 2);
				if (h1 == h2) {
					out.println("Yes");
					continue test;
				}
			}
			out.println("No");
		}
	}
}
