var
  tests, n, i, j : integer;
  a : array[1..200000] of integer;
  good, found : boolean;
begin
  reset(input, 'glade.in');
  rewrite(output, 'glade.out');
  read(tests);
  while (tests > 0) do begin
    tests := tests - 1;
    read(n);
    for i := 1 to n do begin
      read(a[i]);
      a[i + n] := a[i];
    end;
    found := false;
    if (n mod 2 = 0) then begin
      for i := 1 to n div 2 do begin
        good := true;
        for j := 1 to n div 2 do begin
          if (a[i + j - 1] <> a[i + n - j]) then begin
            good := false;
            break;
          end;
        end;
        if (good) then begin
          writeln('Yes');
          found := true;
          break;
        end;
      end;
    end;
    if (not found) then begin
      for i := 1 to n do begin
        good := true;
        for j := 1 to (n - 1) div 2 do begin
          if (a[i + j - 1] <> a[i + n - j - 1 + n mod 2]) then begin
            good := false;
            break;
          end;
        end;
        if (good) then begin
          writeln('Yes');
          found := true;
          break;
        end;
      end;
    end;
    if (not found) then begin
      writeln('No');
    end;
  end;
end.