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

public class glade_ats implements Runnable {
    public static void main(String[] args) {
        (new glade_ats()).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());
    }

    final long p = 37;
    final long base = (int) 1e9 + 7;
    int n;
    long[] h;
    long[] revH;
    long[] pow;

    public long getHash(int l, int r) {
        if (l == 0) {
            return h[r];
        } else {
            return ((h[r] - h[l - 1] * pow[r - l + 1]) % base + base) % base;
        }
    }

    public long getRevHash(int l, int r) {
        if (r == n * 2 - 1) {
            return revH[l];
        } else {
            return ((revH[l] - revH[r + 1] * pow[r - l + 1]) % base + base)
                    % base;
        }
    }

    public void solve() throws IOException {
        n = nextInt();
        assert (2 <= n && n <= (int)1e5);

        int[] s = new int[n * 2];
        for (int i = 0; i < n; i++) {
            s[i] = nextInt();
            assert(s[i] == 0 || s[i] == 1);

            s[i + n] = s[i];
        }
        pow = new long[n * 2];
        pow[0] = 1;
        for (int i = 1; i < s.length; i++) {
            pow[i] = (pow[i - 1] * p) % base;
        }
        h = new long[n * 2];
        h[0] = s[0];
        for (int i = 1; i < s.length; i++) {
            h[i] = (h[i - 1] * p + s[i]) % base;
        }
        revH = new long[n * 2];
        revH[n * 2 - 1] = s[n * 2 - 1];
        for (int i = n * 2 - 2; i >= 0; i--) {
            revH[i] = (revH[i + 1] * p + s[i]) % base;
        }

        if (n % 2 == 0) {
            for (int left = 0; left < n; left++) {
                int mid = left + n / 2 - 1;
                if (getRevHash(left, mid) == getHash(mid + 1, left + n - 1)
                        || getRevHash(left, mid - 1) == getHash(mid + 1, left
                                + n - 2)) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        } else {
            for (int left = 0; left < n; left++) {
                int mid = left + n / 2;
                long v1 = getHash(mid + 1, left + n - 1);
                long v2 = getRevHash(left, mid - 1);
                if (v1 == v2) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }

    public void run() {
        try {
            Locale.setDefault(Locale.US);
            br = new BufferedReader(new FileReader("glade.in"));
            out = new PrintWriter("glade.out");

            int t = nextInt();
            assert (1 <= t && t <= 10);

            for (int i = 0; i < t; i++) {
                solve();
            }

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