{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"Your task is to determine whether sequence X has an echo subsequence of length at least 3. \nSubsequence: Remove k(0\u003c\u003dk\u003c\u003dn) elements from a sequence x of length n to obtain a new sequence that is a subsequence of x \n"}},{"title":"Input","value":{"format":"MD","content":"The first line of input contains an integer T (1≤t≤100) representing the number of test cases. The next 2T line describes the test case. The first line of the test case contains an integer n (3≤n≤5000) representing the length of the array X. The second line of the test case contains n integers X1, x2... Xn of 1≤xi≤n, where Xi is the i-th element of x. \nInsure all test cases(∑n≤5000)。"}},{"title":"Output","value":{"format":"MD","content":"For each test case, print the answer \"YES\" (without quotes) if one of the subsequences of x is at least 3 in length and palindrome, or \"NO\" otherwise. "}},{"title":"Example","value":{"format":"MD","content":"\u003cdiv class\u003d\"sample-test\"\u003e \n \u003cdiv class\u003d\"input\"\u003e \n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e \n \u003cpre\u003e5\n3\n1 2 1\n5\n1 2 2 3 2\n3\n1 1 2\n4\n1 2 2 1\n10\n1 1 2 2 3 3 4 4 5 5\n\u003c/pre\u003e\n \u003c/div\u003e \n \u003cdiv class\u003d\"output\"\u003e \n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e \n \u003cpre\u003eYES\nYES\nNO\nYES\nNO\n\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"MD","content":"In the first test case of this example, the subsequence [1,2,1] of array x is a palindrome. \n \nIn the second test case of the example, the array x has two subsequences of length 3, which are palindromes: [2,3,2] and [2,2,2]. \n \nIn the third test case of this example, array X has no subsequence of at least 3 length and is palindrome. \n \nIn the fourth test case of the example, a subsequence of length 4 of array x is a palindrome: [1,2,2,1]. \n \nIn the fifth test case of the example, the array X has no subsequence of length at least 3 and is palindrome. "}}]}