The following languages are only available languages for the problems from the contest

Kotlin Heroes: Episode 6:

- Kotlin 1.4.0

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Palindromic Doubles

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputA subsequence is a sequence that can be obtained from another sequence by removing some elements without changing the order of the remaining elements.

A palindromic sequence is a sequence that is equal to the reverse of itself.

You are given a sequence of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. Any integer value appears in $$$a$$$ no more than twice.

What is the length of the longest palindromic subsequence of sequence $$$a$$$?

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases.

Then the descriptions of $$$t$$$ testcases follow.

The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 250\,000$$$) — the number of elements in the sequence.

The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$).

Any integer value appears in $$$a$$$ no more than twice. The sum of $$$n$$$ over all testcases doesn't exceed $$$250\,000$$$.

Output

For each testcase print a single integer — the length of the longest palindromic subsequence of sequence $$$a$$$.

Example

Input

5 6 2 1 3 1 5 2 6 1 3 3 4 4 1 1 1 2 1 1 7 4 4 2 5 7 2 3

Output

5 4 1 2 3

Note

Here are the longest palindromic subsequences for the example testcases:

- 2 1 3 1 5 2
- 1 3 3 4 4 1 or 1 3 3 4 4 1
- 1
- 1 1
- 4 4 2 5 7 2 3 or 4 4 2 5 7 2 3

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/18/2021 02:08:35 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|