**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
#include <iostream>
#include <vector>
#include <algorithm>
//#define ll long long
using namespace std;

int main() {
    int test;
    cin >> test;
    for (int t = 0; t < test; t++) {
        int n;
        cin >> n;
        vector<int> a(n);

        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<int> b = a;
        int c = 0;

        for (int i = 0, k = n - 1; i < n; i++) {

            b.erase(unique(b.begin(), b.end()), b.end());
            //cout<<b[i];

            if (b.size() == 1) {
                c = -1 ;
                cout << c<< endl;
                break;
            }

            while (k >= 0 && a[i] == a[k]) {
                //cout<<a[i]<<a[k]<<endl;
                //a.erase(a.begin() + k);

                //k--;
                i++;
                c++;
            }

            cout << c << endl;
            break;
        }for (int i = 0, k = n - 1; i < n; i++) {
            sort(b.begin(), b.end());
            //cout<<a[i];
        }

    }
    return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
3
4
1 2 1 2
6
2 2 2 2 2 2
5
3 4 3 4 3
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long ll;
//#define int long long

const int mod = 7 + 1e9;

int a[300005];

void solve()
{
	int n;
	cin >> n;
	vector<int>v;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] != a[1])
		{
			v.push_back(i);
		}
	}
	if (v.empty())
	{
		cout << -1 << '\n';
		return;
	}
	int s = 1, e = n;
	int cnt = 1;
	int ans1 = 0;
	while (a[s] == a[e])
	{
		e--;
		ans1++;
	}
	int ans2 = 0;
	s = 1, e = n;
	while (a[s] == a[e])
	{
		s++;
		ans2++;
	}

	int ans = min(ans1, ans2);

	for (int i = 1; i < v.size(); i++)
	{
		ans = min(ans, v[i] - v[i - 1]);
	}

		cout << ans;
	cout << '\n';
}

signed main()
{
	int t;
	cin >> t;
	while (t--)solve();
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To generate a challenging test input that exposes the bug in the provided code, let's consider the following aspects:

1. **Edge Cases:**
   - Arrays with all elements the same.
   - Arrays with a single element.
   - Arrays where the first and last elements are different from the middle elements.

2. **Critical Scenarios:**
   - Arrays where the minimum number of removals is required to make the array non-beautiful.
   - Arrays where the minimum number of removals is not straightforward and requires careful consideration.

Given the constraints and the nature of the problem, let's create a test input that includes these aspects:

### Test Input
```plaintext
3
5
1 2 1 2 1
7
3 3 3 4 3 3 3
3
2 2 2
```

### Explanation
1. **Test Case 1:**
   - Array: `[1, 2, 1, 2, 1]`
   - This array is beautiful. By removing the element at index 5, the array becomes `[1, 2, 1, 2]`, which is not beautiful.
   - Expected output: `1`

2. **Test Case 2:**
   - Array: `[3, 3, 3, 4, 3, 3, 3]`
   - This array is beautiful. By removing the first three elements, the array becomes `[4, 3, 3, 3]`, which is not beautiful.
   - Expected output: `3`

3. **Test Case 3:**
   - Array: `[2, 2, 2]`
   - This array is beautiful and consists of identical elements. It is impossible to make it non-beautiful by removing elements.
   - Expected output: `-1`

This test input covers a variety of scenarios and should help expose any issues in the provided buggy code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
def solve():
    n = int(input().strip())
    arr = list(map(int, input().split()))
    if arr != arr[::-1]:
        print(0)
        return
    prev = arr[-1]
    i = n-2
    res = 1
    while i >= 0 and prev == arr[i]:
        res += 1
        i -= 1
    if i == -1:
        print(i)
        return
    print(res)

    return

def main():
    test = int(input())
    for t in range(test):
        solve()

    # solve()

if __name__ == "__main__":
    main()

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To create a test input that exposes the bug in the given buggy code, let's analyze the issues and edge cases:

1. **Symmetry Check**: The code checks if the array is a palindrome. If it's not, it immediately returns 0, which is incorrect. The array can still be beautiful without being a palindrome.
2. **Trivial Cases**: The code handles trivial cases (like all elements being the same) incorrectly. It should return -1 if all elements are the same.
3. **Edge Cases**: The code does not handle edge cases well, such as arrays with a small number of elements or specific patterns that make it difficult to break the beauty condition.

### Test Input

Let's create a test input that includes these edge cases:

1. **Palindrome but not all elements the same**:
   - Example: `5 1 2 1 2 1` (This should require removing 1 element to break the beauty condition)

2. **All elements the same**:
   - Example: `3 2 2 2` (This should return -1)

3. **Non-palindrome but still beautiful**:
   - Example: `7 3 3 3 5 3 3 3` (This should require removing 3 elements to break the beauty condition)

4. **Single element array**:
   - Example: `1 1` (This should return -1)

5. **Array with a different pattern**:
   - Example: `4 1 2 2 1` (This should require removing 1 element to break the beauty condition)

### Complete Test Input

```plaintext
5
5
1 2 1 2 1
3
2 2 2
7
3 3 3 5 3 3 3
1
1
4
1 2 2 1
```

This test input covers various edge cases and should expose the bugs in the given buggy code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    st = set(a)
    if len(st) == 1:
        print(-1)
        continue

    left = 0
    for i in range(n):
        if a[i] != a[n-1]:
            break
        left += 1

    right = 0
    for i in range(n-1, -1, -1):
        if a[i] != a[0]:
            break
        right += 1

    print(min(left, right))

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
3
5
1 2 1 2 1
6
1 1 2 1 1 1
7
3 3 3 5 3 3 3
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
t=int(input())

for i in range(t):
    n=int(input())
    l1=input().split()
    for i in range(len(l1)):
        l1[i]=int(l1[i])

    flag=True
    for i in l1:
        if(i!=l1[0]):
            flag=False
            break

    if(flag==True):
        print(-1)
    else:
        count1=0
        for i in range(len(l1)):
            if(l1[i]==l1[0]):
                count1+=1
            else:
                break
        count2=0
        for i in range(-1,-(len(l1)+1),-1):
            if(l1[i]==l1[-1]):
                count2+=1
            else:
                break
        print(min(count1,count2))

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
3
5
1 2 1 2 1
6
1 2 2 1 2 2
7
1 2 1 3 1 2 1
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
import java.util.Scanner;

public class Tent {
    public static int help(int[] ar){
        int nik=0;
        int i=0;
        while(ar[i]==ar[ar.length-1] && i!=ar.length-1){
            nik++;
            i++;
        }
        if(ar[i]==ar[ar.length-1]) return -1;
        return nik;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++){
            int a= sc.nextInt();
            int[] ar = new int[a];
            for(int ii=0;ii<a;ii++){
                ar[ii]=sc.nextInt();
            }
            int l=help(ar);
            int[] br = new int[a];
            for(int ii=0;ii<a;ii++){
                br[ii]=ar[a-ii-1];
            }
            int m=help(br);
            if(l==-1 && m==-1){
                System.out.println(-1);
            } else {
                System.out.println(Math.min(l,m));
            }
        }
    }
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
3
4
1 1 1 1
6
1 2 1 2 1 2
5
3 3 3 3 3
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
import java.util.ArrayList;
import java.util.Scanner;

public class MakeItUgly {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int a[] = new int[n];
            int b[] = new int[n];
            for (int i = 0; i < a.length; i++) {
                a[i] = sc.nextInt();
                b[i] = a[i];
            }
            for (int i = 1; i < b.length - 1; i++) {
                if (b[i + 1] == b[i - 1]) {
                    b[i] = b[i - 1];
                }
            }
            boolean flag = true;
            for (int i = 1; i < b.length; i++) {
                if (b[i] != b[i - 1]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                ArrayList<Integer> index = new ArrayList<Integer>();
                for (int i = 1; i < a.length - 1; i++) {
                    if (a[i - 1] == a[i + 1] && a[i] != a[i - 1]) {
                        index.add(i);
                    }
                }
                int min = Integer.MAX_VALUE;
                for (int i = 1; i < index.size(); i++) {
                    min = Math.min(index.get(i) - index.get(i - 1), min);
                }
                if (index.size() == 0) {
                    System.out.println(-1);
                } else if (index.size() == 1) {
                    min = Math.min(index.get(0), n - index.get(0) - 1);
                    System.out.println(min);
                } else {
                    min = min == 1 ? 2 : min;
                    System.out.println(min - 1);
                }
            } else {
                System.out.println(0);
            }
        }
    }
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
```

This test input is designed to cover various scenarios that can expose the bug in the provided buggy code. Here's a breakdown of the test cases:

1. **Test Case 1: All elements are the same**
   - Input: `3 2 2 2`
   - Expected Output: `-1`
   - Reason: The array is already beautiful and cannot be made non-beautiful by removing any elements.

2. **Test Case 2: Elements can be made non-beautiful by removing one element**
   - Input: `5 1 2 1 2 1`
   - Expected Output: `1`
   - Reason: Removing the last element (index 4) makes the array non-beautiful.

3. **Test Case 3: Single element array**
   - Input: `1 1`
   - Expected Output: `-1`
   - Reason: A single element array is already beautiful and cannot be made non-beautiful by removing elements.

4. **Test Case 4: Multiple elements with a different middle element**
   - Input: `7 3 3 3 5 3 3 3`
   - Expected Output: `3`
   - Reason: Removing the first three elements (indices 0, 1, 2) makes the array non-beautiful.

These test cases cover a range of scenarios, including arrays with all elements the same, arrays that can be made non-beautiful by removing one element, single-element arrays, and arrays with a different middle element. Each test case is designed to challenge the buggy code and reveal its flaws.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 10000000007
void solve(){
    ll n;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++){
        cin>>v[i];
    }
    set<ll>st;
    for(auto i:v){
        st.insert(i);
    }
    if(st.size()==1){
        cout<<-1<<endl;
        return;
    }
        ll i;
        ll t;
      for(i=1;i<n;i++){
        if(v[i-1]!=v[i]){
            t=v[i-1];
           break;
        }
      }
        ll cnt=0;
          ll j;
            for( j=i+1;j<n;j++){
                if(v[j]!=t){
                    break;
            }
        }

        ll ans=j-i-1;
      if(ans>0){
        cout<<ans<<endl;
      }else{
        cout<<-1<<endl;
      }

    }

signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
    ll t;
     cin>>t;
while(t--){
  solve();}
 return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
5
4
1 2 1 2
6
1 2 1 2 1 2
7
1 2 1 2 1 2 1
8
1 2 1 2 1 2 1 2
9
1 2 1 2 1 2 1 2 1
```

### Explanation:
1. **Test Case 1 (n=4):** `1 2 1 2`
   - This array is already not beautiful, as it cannot be made all the same with the given operations. The correct output should be `0`, but the buggy code might not handle this correctly.

2. **Test Case 2 (n=6):** `1 2 1 2 1 2`
   - This array is not beautiful and cannot be made beautiful by removing any elements. The correct output should be `0`, but the buggy code might not handle this correctly.

3. **Test Case 3 (n=7):** `1 2 1 2 1 2 1`
   - This array is beautiful. The correct output should be `1`, but the buggy code might not handle this correctly.

4. **Test Case 4 (n=8):** `1 2 1 2 1 2 1 2`
   - This array is beautiful. The correct output should be `1`, but the buggy code might not handle this correctly.

5. **Test Case 5 (n=9):** `1 2 1 2 1 2 1 2 1`
   - This array is beautiful. The correct output should be `1`, but the buggy code might not handle this correctly.

These test cases are designed to challenge the buggy code by focusing on edge cases where the array is already not beautiful or where the minimum number of elements to remove is 1.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int solve(){
    int n; cin>>n; vector<int> v(n, 0);
    for(int i = 0;i<n;i++) cin>>v[i];
    int sd = 0;
    for(;sd<n && v[sd]==v[0];sd++){};
    if(sd == n) return -1;
    int ed = n-1;
    for(;ed>=0 && v[ed]==v[n-1];ed--){};
    return min(sd, n-ed-1);
}

int main() {
    int T; cin>>T;
    while(T){T--;
        cout<<solve()<<"\n";
    }
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To generate a challenging test input that exposes the bug in the provided code, we need to consider the following points:

1. **Array with all elements the same**: The code correctly handles this case by returning -1.
2. **Array with a mix of elements**: The code should handle this by finding the minimum number of elements to remove to make the array non-beautiful. However, the code might fail if the array has a pattern that it does not correctly identify.

Let's consider an array where the elements are not all the same, but the code might incorrectly identify a segment that it thinks can be removed to make the array non-beautiful. A good candidate for this is an array where the elements are mostly the same, but with a few different elements in the middle.

### Challenging Test Input
```plaintext
1
7
1 2 2 2 2 2 1
```

### Explanation
- **Array**: `[1, 2, 2, 2, 2, 2, 1]`
- **Description**: This array is beautiful because you can apply the operation to make all elements the same. However, the code might incorrectly identify the segment of `2`s as a part that can be removed to make the array non-beautiful.

### Expected Output
- **Correct Output**: `3`
- **Explanation**: To make the array non-beautiful, you need to remove at least 3 elements. For example, removing the first, fourth, and seventh elements results in the array `[2, 2, 2, 2]`, which is not beautiful.

### Why This Input is Challenging
- The code might incorrectly identify the segment of `2`s as a part that can be removed without considering the entire structure of the array.
- This input tests the code's ability to correctly identify and handle segments of the array that need to be removed to make it non-beautiful.

This test input should help expose the bug in the provided code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
for _ in range(int(input())):
    n = int(input())
    a = [int(x) for x in input().split()]
    ele = a[0]
    for i in range(len(a)):
        if a[i] == ele:
            a[i] = 1
        else:
            a[i] = 0
    number = a.count(0)
    if number == 0:
        print(-1)
        continue
    zeroes = []
    counter = 0
    for i in range(len(a)):
        if a[i] == 1:
            counter += 1
        else:
            if zeroes:
                zeroes.append(counter - zeroes[-1])
            else:
                zeroes.append(counter)
    zeroes.append(counter - zeroes[-1])
    print(min(zeroes))

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To create a challenging test input that exposes the bug in the given buggy code, we need to focus on edge cases and scenarios that maximize the failure probability. The buggy code has a few key issues:

1. **Incorrect Transformation of Array Elements**: The code transforms the array elements to 1 and 0 based on whether they match the first element. This transformation is not necessary and can lead to incorrect results.
2. **Incorrect Calculation of Minimum Removals**: The code attempts to calculate the minimum number of removals by counting sequences of 1s and 0s, but it does not correctly handle the conditions for making the array non-beautiful.

To expose these issues, we can create a test case where the array is already beautiful and the minimum number of removals is not straightforward to determine. Here is a small-scale test input that should challenge the buggy code:

```plaintext
4
3
1 1 1
5
1 2 1 2 1
6
1 2 1 2 1 2
7
1 2 3 2 1 2 1
```

### Explanation:
1. **Test Case 1 (3 1 1 1)**:
   - The array is already beautiful, and it is impossible to make it non-beautiful by removing elements. The correct output should be `-1`.

2. **Test Case 2 (5 1 2 1 2 1)**:
   - The array is beautiful. Removing any single element will make it non-beautiful. The correct output should be `1`.

3. **Test Case 3 (6 1 2 1 2 1 2)**:
   - The array is beautiful. Removing any single element will make it non-beautiful. The correct output should be `1`.

4. **Test Case 4 (7 1 2 3 2 1 2 1)**:
   - The array is beautiful. Removing the middle element (3) will make it non-beautiful. The correct output should be `1`.

This test input includes various edge cases and should expose the bugs in the given code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
def solve(arr = []):
    n = len(arr)
    ans = n+1
    def akk(arr = [],a = 0):
        nonlocal ans
        # print(arr)
        if arr[0] != arr[len(arr)-1]:
            ans = min(ans,a)
            return
        if len(arr) <= 2:
            return
        akk(arr[0:len(arr)-1],a+1)
        akk(arr[1:len(arr)],a+1)

    akk(arr,0)
    if ans == n+1:
        print(-1)
    else:
        print(ans)

def solve2(arr = []):
    n = len(arr)
    i = 0
    j = n-1
    ans = 0

    while n-1>i and arr[i] == arr[i+1]:
            i+=1

    while 0<j and arr[j] == arr[j-1]:
            j-=1

    if i >= j:
        print(-1)
    else :
        print(min(i+1,j+1))

for t in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    if t == 824:
        print(a)
    else:
        solve2(a)

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
5
3
1 2 1
4
1 2 2 1
5
1 2 1 2 1
6
1 1 2 2 1 1
7
1 2 2 3 3 2 1
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Scanner;

    public class B_Make_It_Ugly {

        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int t=sc.nextInt();
            while (t-->0) {
                int n=sc.nextInt();
                int arr[]=new int[n];
                HashMap<Integer,Integer> map=new HashMap<>();
                int max=0;
                int val=-1;
                for (int i = 0; i < arr.length; i++) {
                    arr[i]=sc.nextInt();
                    map.put(arr[i],map.getOrDefault(arr[i], 0)+1);
                    if(max<map.get(arr[i])){
                        max=map.get(arr[i]);
                        val=arr[i];
                    }
                }
                // System.out.println(val);
                if(map.size()==1 || n<=2){
                    System.out.println(-1);
                }else{
                    int min=Integer.MAX_VALUE;
                    int count=0;
                    for (int i = 0; i < arr.length; i++) {
                        if(arr[i]==val){
                            count++;
                        }else{
                            min=Math.min(count,min);
                            count=0;

                        }
                    }
                    System.out.println(min);
                }
            }
        }
    }

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
3
4
1 2 1 2
6
1 2 1 3 1 3
5
1 1 1 1 1
```

### Explanation:
1. **Test Case 1:**
   - Array: `[1, 2, 1, 2]`
   - This array is already not beautiful because there are no indices `i` (2 ≤ i ≤ 3) where `a[i-1] = a[i+1]`. Hence, the minimum number of elements to remove is 0, but since the output is expected to be -1 if it's already not beautiful, the correct output is -1.

2. **Test Case 2:**
   - Array: `[1, 2, 1, 3, 1, 3]`
   - This array is beautiful because you can apply the operation to make it all the same. However, to make it not beautiful, you need to remove one element. For example, removing the second element (2) results in `[1, 1, 3, 1, 3]`, which is not beautiful. The correct output is 1.

3. **Test Case 3:**
   - Array: `[1, 1, 1, 1, 1]`
   - This array is beautiful because all elements are the same. It is impossible to make it not beautiful by removing any elements. The correct output is -1.

These test cases are designed to cover different scenarios:
- An array that is already not beautiful.
- An array that can be made not beautiful by removing one element.
- An array that cannot be made not beautiful by any removals.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Formatter.BigDecimalLayoutForm;

import javax.swing.text.NavigationFilter;

import java.math.BigInteger;

public class Main{
    public static class Pair {
        int value;
        int index;
        Pair(int x, int y){
            this.value = x;
            this.index = y;
        }
    }
    public static int findMex(int[] array) {
        int n = array.length;
        boolean[] present = new boolean[n + 1];
        for (int i = 0; i < n; i++) {
            if (array[i] >= 0 && array[i] <= n) {
                present[array[i]] = true;
            }
        }
        for (int i = 0; i <= n; i++) {
            if (!present[i]) {
                return i;
            }
        }
        return n + 1;
    }

    public static void sortedInsert(ArrayList<Integer> list, int element) {
        int index = Collections.binarySearch(list, element);
        if (index < 0) {
            index = -(index + 1);
        }
        list.add(index, element);
    }

    public static int countDifferentCharacters(String str1, String str2) {
        int count = 0;

        // Iterate over each character and compare
        for (int i = 0; i < str1.length(); i++) {
            if (str1.charAt(i) != str2.charAt(i)) {
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
       MyScanner sc = new MyScanner();
       out = new PrintWriter(new BufferedOutputStream(System.out));

       // Start writing your solution here. -------------------------------------

       /*
       int n      = sc.nextInt();        // read input as integer
       long k     = sc.nextLong();       // read input as long
       double d   = sc.nextDouble();     // read input as double
       String str = sc.next();           // read input as String
       String s   = sc.nextLine();       // read whole line as String

       int result = 3*n;
       out.println(result);                    // print via PrintWriter
       */

       /*
            String str[] = sc.nextLine().split(" ");
            BigInteger ele[] = new BigInteger[n];
            int k = 0;
            for(int i=0;i<str.length;i++){
                if(str[i]==" " || str[i]==""){
                    continue;
                }
                ele[k] = new BigInteger(str[i]);
                k++;
            }
        */
        /* for sorting array with 2D
         *
         *
         *
         *   Arrays.sort(array, Comparator.comparingInt(paid -> paid.key));
         *
         */
       int t = sc.nextInt();

       ArrayList<Integer> arr = new ArrayList<>();

       for(int j=0;j<t;j++){
            int n = sc.nextInt();
            int ele[] = new int[n];
            for(int i=0;i<n;i++){
                ele[i] = sc.nextInt();
            }
            if(ele.length==1){
                arr.add(-1);
                continue;
            }
            if(ele.length==2 && ele[0] == ele[1]){
                arr.add(-1);
                continue;
            }
            ArrayList<Pair> newElements = new ArrayList<>();
            Pair p0 = new Pair(1, ele[0]);
            newElements.add(p0);
            for(int i=1;i<n;i++){
                if(ele[i]==ele[i-1]){
                    newElements.get(newElements.size()-1).value = newElements.get(newElements.size()-1).value + 1;
                }else{
                    Pair p1 = new Pair(1, ele[i]);
                    newElements.add(p1);
                }
            }
            if(newElements.size()<3){
                arr.add(-1);
                continue;
            }
            boolean pos = false;
            int count = Integer.MAX_VALUE;
            for(int i=1;i<newElements.size()-1;i++){
                if(newElements.get(i-1).index != newElements.get(i+1).index){
                    pos = true;
                    count = Math.min(count, newElements.get(i).value );
                }else{
                    pos = true;
                    count = Math.min(count, Math.min(newElements.get(i+1).value , newElements.get(i-1).value ) );
                }
            }
            if(pos){
                arr.add(count);
            }else{
                arr.add(-1);
            }
       }

       for(int i=0;i<arr.size();i++){
           System.out.println(arr.get(i));
       }
  }

  //-----------PrintWriter for faster output---------------------------------
  public static PrintWriter out;

  //-----------MyScanner class for faster input----------
  public static class MyScanner {
     BufferedReader br;
     StringTokenizer st;

     public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
     }

     String next() {
         while (st == null || !st.hasMoreElements()) {
             try {
                 st = new StringTokenizer(br.readLine());
             } catch (IOException e) {
                 e.printStackTrace();
             }
         }
         return st.nextToken();
     }

     int nextInt() {
         return Integer.parseInt(next());
     }

     long nextLong() {
         return Long.parseLong(next());
     }

     double nextDouble() {
         return Double.parseDouble(next());
     }

     String nextLine(){
         String str = "";
     try {
        str = br.readLine();
     } catch (IOException e) {
        e.printStackTrace();
     }
     return str;
     }

  }
  //--------------------------------------------------------
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To generate a challenging test input that exposes the bug in the provided buggy code, we need to focus on edge cases and scenarios that are likely to cause the algorithm to fail. Here are the steps to think through this:

1. **Understand the Bug**: The buggy code seems to have issues with handling arrays where the elements are not easily reducible to a non-beautiful state. Specifically, it might not handle cases where the array is already in a state where no further operations can make it non-beautiful.

2. **Edge Cases**:
   - **Single Element Array**: The code should handle this case correctly by returning -1.
   - **Two Element Array with Identical Elements**: The code should handle this case correctly by returning -1.
   - **Array with All Elements Identical**: The code should return -1.
   - **Array with a Pattern that is Hard to Break**: For example, an array like [1, 2, 1, 2, 1, 2, 1] where it is difficult to remove elements to break the pattern.

3. **Generate Test Input**:
   - We will create a test case with a small number of test cases (since the output length is limited).
   - Each test case will be designed to challenge the algorithm in different ways.

Here is a small-scale test input that includes various edge cases:

```plaintext
3
1
1
2
1 1
7
1 2 1 2 1 2 1
```

### Explanation:
1. **Test Case 1**:
   - Input: `1 1`
   - Expected Output: `-1`
   - Reason: A single-element array cannot be made non-beautiful by removing elements.

2. **Test Case 2**:
   - Input: `2 1 1`
   - Expected Output: `-1`
   - Reason: An array with two identical elements cannot be made non-beautiful by removing elements.

3. **Test Case 3**:
   - Input: `7 1 2 1 2 1 2 1`
   - Expected Output: `3`
   - Reason: This array has a pattern that is hard to break. Removing the middle elements (e.g., the third, fifth, and seventh elements) will make it non-beautiful.

This test input should help expose the bug in the provided code by covering various edge cases and challenging scenarios.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
/* :::::::         ::.     .:::::::.    ::.    .:^:       .::     ::
  .#@#BB#&#Y:     ?@@G.    J@&#BBB##5: .#@J  .Y&&Y:       5@&Y   :&&^
  .&@Y ..^G@#:   !@#G@P    Y@&.   ~@@J .&@J.J&&Y^         5@@@G: :@@~
  .&@J    ^@@7  :&@~ B@J   Y@@PPPPB&G^ .&@B#@@P           5@GJ@&~:&@~
  .&@J    ~@@! .B@&YYB@@7  Y@&??P@&J   .&@&J^G@B^   YBGG5 5@P !&@Y&@~
  .&@P~~!?#@5  P@B?JJJ5@@~ Y@&.  !&@G^ .&@Y   Y@@J  ~!!!~ 5@P  ^B@@@~
  .PGGGGGGY~  !BG^     YB5 7BP.   :5BP:.PB7    ?BB?       JBJ   .YBG^
*/
#include<bits/stdc++.h>
#define endlflush endl
#define debug(x) cout << #x << " " << x << endlflush;
#define endl '\n'
#define needForSpeed ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef  long long int ll;
typedef  long double ld;
typedef unsigned long long int ull;
using namespace std;
// using u64 = uint64_t;
// using u128 = __uint128_t;
void files()
{
    // freopen("input.in","r",stdin);
    // freopen("output.out","w",stdout);
}
/*-----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------*/
int main()
{
    // files();
    needForSpeed
    ll t; cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        vector<ll> v(n),temp(n);
        for(ll i=0;i<n;i++)
        {
            cin >> v[i];
            temp[i]=v[i];
        }
        bool isSame=true;
        for(ll i=1;i<n;i++)
            isSame&=(v[i]==v[i-1]);
        if(isSame)
        {
            cout << -1 << endl;
            continue;
        }
        bool isBeautiful=true;
        for(ll i=1;i<n-1;i+=2)
        {
            isBeautiful&=(v[i+1]==v[i-1]);
            v[i]=v[i-1];
        }
        isBeautiful&=(n>2);
        if(!isBeautiful)
        {
            cout << 0 << endl;
            continue;
        }
        ll ans=n;
        for(ll i=1;i<n;i++)
        {
            if(temp[i]!=temp[i-1])
            {
                ans=min(ans,(i));
                break;
            }
        }
        for(ll i=n-2;i>=0;i--)
        {
            if(temp[i]!=temp[i+1])
            {
                ans=min(ans,n-(i+1));
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To create a challenging test input that exposes the bug in the given code, we need to focus on edge cases and scenarios that can maximize the failure probability. The code has several potential issues, such as:

1. **Handling arrays where all elements are the same**.
2. **Handling arrays where elements can be made the same using the given operation**.
3. **Handling arrays where the minimum number of elements to remove is not straightforward**.

Let's construct a test case that can expose these issues:

### Test Case 1: All Elements are the Same
This should return -1 because it's impossible to make the array not beautiful by removing elements.

```plaintext
1
3
2 2 2
```

### Test Case 2: Elements Can Be Made the Same Using the Operation
This should return a non-zero value because the array can be made not beautiful by removing a specific element.

```plaintext
1
5
1 2 1 2 1
```

### Test Case 3: Complex Array with Multiple Possible Solutions
This should return the minimum number of elements to remove to make the array not beautiful.

```plaintext
1
7
3 3 3 5 3 3 3
```

### Test Case 4: Edge Case with Single Element
This should return -1 because a single-element array is always beautiful and cannot be made not beautiful by removing elements.

```plaintext
1
1
1
```

### Test Case 5: Edge Case with Two Elements
This should return 0 because a two-element array that is beautiful cannot be made not beautiful by removing elements.

```plaintext
1
2
1 1
```

### Test Case 6: Complex Array with Multiple Possible Solutions
This should return the minimum number of elements to remove to make the array not beautiful.

```plaintext
1
10
1 2 1 3 1 2 1 3 1 2
```

### Final Test Input
Combining all these test cases, the final test input is:

```plaintext
6
3
2 2 2
5
1 2 1 2 1
7
3 3 3 5 3 3 3
1
1
2
1 1
10
1 2 1 3 1 2 1 3 1 2
```

This input covers a range of scenarios and should help expose any bugs in the code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
#include <bits/stdc++.h>
using namespace std;
#define all(s) (s).begin(),(s).end()
#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define nl "\n"
#define pb push_back

void solve() {
	ll n;
	cin >> n;
	vll a(n);
	for(auto& ai: a) cin >> ai;
	ll ans = -1;
	map<ll, ll> mp;
	for(auto ai: a) ++mp[ai];
	ll mxkey = - 1;
	for(auto [key, val] : mp) {
	    if(mxkey == -1) mxkey = key;
	    else {
	        if(val > mp[mxkey]) mxkey = key;
	    }
	}
	ll cnt = 0;
	for(auto ai: a) {
	    if(ai == mxkey) ++cnt;
	    else {
	        if(ans == -1) ans = cnt;
	        else {
	            ans = min(ans, cnt);
	        }
	        cnt = 0;
	    }
	}
	if(cnt && ans != -1) ans = cnt;
	cout << ans << nl;
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
	ll t = 1;
	cin >> t;
	while(t--) {
		solve();
	}
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
5
1 1 2 1 1
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
# for _ in range(int(input())):
#     a,b,c=map(int,input().split())
#     # temp=a//b
#     temp=a//b
#     if a%b:
#         temp+=1
#     if c>=a-temp:
#         print("NO")
#     else:
#         print("YES")
for _ in range(int(input())):
    a=int(input())
    l=list(map(int,input().split()))
    if len(set(l))==1:
        print('-1')
    else:
        temp=l[0]
        ans1=0
        ans2=0
        for i in range(a):
            if l[i]==temp:
                ans1+=1
            else:
                break
        for i in range(a-1,-1,-1):
            if l[i]==temp:
                ans2+=1
            else:
                break
        print(min(ans1,ans2))

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    kl = 0
    kr = 0
    for i in a:
        if(i!=a[0]):
            break
        kl+=1
    for i in a[::-1]:
        if(i!=a[-1]):
            break
        kr+=1
    if min(kl, kr)!=len(a):
        print(min(kl, kr))
    else:
        print(-1)

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To generate a test input that exposes the bug in the provided code, we need to consider the logic and potential edge cases where the code might fail. The code attempts to count the number of elements at the beginning and end of the array that are equal to the first and last elements, respectively, and then outputs the minimum of these counts. If both counts are equal to the length of the array, it outputs -1.

### Key Points to Consider:
1. **All Elements Are the Same**: If all elements are the same, the code will output -1, which is correct.
2. **Non-Uniform Array**: If the array is not uniform, the code might incorrectly count the elements at the beginning and end.
3. **Edge Cases**: Consider arrays where the elements at the beginning and end are different from the rest of the array.

### Chosen Test Case:
Let's create a test case where the array starts and ends with a different element, but the middle part is uniform. This should expose the bug in the code.

### Test Input:
```plaintext
1
7
1 2 2 2 2 2 1
```

### Explanation:
- **Input**: `1 7 1 2 2 2 2 2 1`
- **Expected Output**: `1`

### Why This Test Case?
- The array starts and ends with `1`, but the middle part is `2`.
- The code will count `1` at the beginning and `1` at the end.
- The code will output `1`, which is correct, but it should be tested to ensure it doesn't output `2` or `-1` incorrectly.

This test case will help verify if the code correctly handles the scenario where the array is beautiful but can be made non-beautiful by removing a single element.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Make It Ugly
time_limit_ms: 2000
memory_limit_mb: 256
Description: Let's call an array $$$a$$$ beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):

- choose an index $$$i$$$ ($$$2 \le i \le |a| - 1$$$) such that $$$a_{i - 1} = a_{i + 1}$$$, and replace $$$a_i$$$ with $$$a_{i - 1}$$$.

You are given a beautiful array $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).

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

Additional constraints on the input:

- in every test case, the given array $$$a$$$ is beautiful;
- the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output: For each test case, output a single integer — the minimum number of elements you have to remove from the array $$$a$$$ in order for it to stop being beautiful. If it is impossible, then output -1.

Examples:
input:
4
3
2 2 2
5
1 2 1 2 1
1
1
7
3 3 3 5 3 3 3
output:
-1
1
-1
3

Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.

In the second testcase, you can remove the number at the index $$$5$$$, for example.

The resulting array will be $$$[1, 2, 1, 2]$$$. Let's check if it is beautiful. Two operations are available:

- Choose $$$i = 2$$$: the array becomes $$$[1, 1, 1, 2]$$$. No more operations can be applied to it, and the numbers are not all the same.
- Choose $$$i = 3$$$ instead: the array becomes $$$[1, 2, 2, 2]$$$. No more operations can be applied to it either, and the numbers are still not all the same.

Thus, the array $$$[1, 2, 1, 2]$$$ is not beautiful.

In the fourth testcase, you can remove the first three elements, for example. The resulting array $$$[5, 3, 3, 3]$$$ is not beautiful.

Buggy Code:
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.io.*;

public class code_chef
{

    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int t = sc.nextInt();
        long M = 1000000007;
        while (t-- > 0) {
            int n=sc.nextInt();
            int arr[]=new int[n];
            newarray(arr);
            HashMap<Integer,Integer>map=new HashMap<>();
            for(int i=0;i<arr.length;i++){
                map.put(arr[i], map.getOrDefault(arr[i], 0)+1);
            }
            if(map.keySet().size()==1){
                System.out.println(-1);
            }else{
                int max=map.get(arr[0]);
                int maxkey=arr[0];
                for(int i=1;i<arr.length;i++){
                    if(map.get(arr[i])>max){
                        max=map.get(arr[i]);
                        maxkey=arr[i];
                    }
                }
                int ind1=-1;
                int ind2=-1;
                int prev=-1;
                int dist=Integer.MAX_VALUE;
                for(int i=0;i<n;i++){
                    if(ind1==-1 && arr[i]!=maxkey){
                        ind1=i;
                        prev=i;
                    }else if(arr[i]!=maxkey){
                        ind2=i;
                        if(prev!=-1){
                            int curr=ind2-prev-1;
                            if(curr<dist){
                                dist=curr;
                            }
                            prev=i;
                        }
                    }
                }
                int ans=Math.min(n-ind2-1,Math.min(ind1,dist));
                System.out.println(ans);
            }
        }
    }

    public static void newarray(int arr[]){
        for(int i=0;i<arr.length;i++){
            arr[i]=sc.nextInt();
        }
    }
    public static void newarray(long arr[]){
        for(int i=0;i<arr.length;i++){
            arr[i]=sc.nextLong();
        }
    }
    public static void printarray(int arr[]){
        for(int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
    public static void printarray(long arr[]){
        for(int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
    public static void countcharacter(int arr[],HashMap<Integer,Integer>map){
        for(int i=0;i<arr.length;i++){
            map.put(arr[i], map.getOrDefault(arr[i], 0)+1);
        }
    }
    public static void countcharacter(long arr[],HashMap<Long,Integer>map){
        for(int i=0;i<arr.length;i++){
            map.put(arr[i], map.getOrDefault(arr[i], 0)+1);
        }
    }
    public static void countcharacter(String str,HashMap<Character,Integer>map){
        for(int i=0;i<str.length();i++){
            map.put(str.charAt(i), map.getOrDefault(str.charAt(i), 0)+1);
        }
    }
    static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
    static long maxSubArraySum(int a[])
    {
        int size = a.length;
        long max_so_far = 0, max_ending_here= 0;
        for (int i = 0; i < size; i++) {
            max_ending_here = max_ending_here + a[i];
            if (max_so_far < max_ending_here)
                max_so_far = max_ending_here;
            if (max_ending_here < 0)
                max_ending_here = 0;
        }
        return max_so_far;
    }
    static long minSubArraySum(int a[])
    {
        int size = a.length;
        long max_so_far = Integer.MAX_VALUE, max_ending_here= 0;
        for (int i = 0; i < size; i++) {
            max_ending_here = max_ending_here + a[i];
            if (max_so_far > max_ending_here)
                max_so_far = max_ending_here;
            if (max_ending_here > 0)
                max_ending_here = 0;
        }
        return max_so_far;
    }
    static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }
    static int lcs(String X, String Y, int m, int n,int[][]dp)
    {
        for (int i = 0; i <= m; i++) {
            for (int j = 0; j <= n; j++) {
                if (i == 0 || j == 0)
                    dp[i][j] = 0;
                else if (X.charAt(i - 1) == Y.charAt(j - 1))
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        return dp[m][n];
    }
    public static List<Integer> searchPattern(String text, String pattern) {
        List<Integer> indices = new ArrayList<>();
        int[] lps = computeLPSArray(pattern);

        int i = 0;
        int j = 0;

        while (i < text.length()) {
            if (pattern.charAt(j) == text.charAt(i)) {
                i++;
                j++;
            }

            if (j == pattern.length()) {
                indices.add(i - j);
                j = lps[j - 1];
            } else if (i < text.length() && pattern.charAt(j) != text.charAt(i)) {
                if (j != 0) {
                    j = lps[j - 1];
                } else {
                    i++;
                }
            }
        }

        return indices;
    }

    private static int[] computeLPSArray(String pattern) {
        int[] lps = new int[pattern.length()];
        int len = 0;
        int i = 1;

        while (i < pattern.length()) {
            if (pattern.charAt(i) == pattern.charAt(len)) {
                len++;
                lps[i] = len;
                i++;
            } else {
                if (len != 0) {
                    len = lps[len - 1];
                } else {
                    lps[i] = 0;
                    i++;
                }
            }
        }

        return lps;
    }
    static void merge(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int[n1];
        int R[] = new int[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            }
            else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    static void mergesort(int arr[], int l, int r)
    {
        if (l < r) {
            int m = l + (r - l) / 2;
            mergesort(arr, l, m);
            mergesort(arr, l, r);
            merge(arr, l, m, r);
        }
    }
private static int mergeAndCount(int[] arr, int l,int m, int r)
    {
        int[] left = Arrays.copyOfRange(arr, l, m + 1);
        int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);

        int i = 0, j = 0, k = l, swaps = 0;

        while (i < left.length && j < right.length) {
            if (left[i] <= right[j])
                arr[k++] = left[i++];
            else {
                arr[k++] = right[j++];
                swaps += (m + 1) - (l + i);
            }
        }
        while (i < left.length)
            arr[k++] = left[i++];
        while (j < right.length)
            arr[k++] = right[j++];
        return swaps;
    }
    private static int mergeSortAndCount(int[] arr, int l,int r)
    {
        int count = 0;

        if (l < r) {
            int m = (l + r) / 2;
            count += mergeSortAndCount(arr, l, m);
            count += mergeSortAndCount(arr, m + 1, r);
            count += mergeAndCount(arr, l, m, r);
        }

        return count;
    }
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To create a challenging test input that exposes the bug in the provided buggy code, we need to focus on edge cases that can cause the code to fail. The key aspects to consider are:

1. **Arrays with all elements the same**: The code should correctly output -1 for these cases.
2. **Arrays with a single unique element**: The code should handle these cases correctly.
3. **Arrays where the minimum removal is not straightforward**: These cases should challenge the logic for finding the minimum number of elements to remove.

Given the constraints and the nature of the problem, let's create a small-scale test input that includes these edge cases.

### Test Input

```plaintext
4
3
1 1 1
5
1 2 1 2 1
6
1 2 1 2 1 2
7
3 3 3 5 3 3 3
```

### Explanation

1. **Test Case 1:**
   - **Input:** `3 1 1 1`
   - **Expected Output:** `-1`
   - **Reason:** All elements are the same, so it is impossible to make the array not beautiful by removing elements.

2. **Test Case 2:**
   - **Input:** `5 1 2 1 2 1`
   - **Expected Output:** `1`
   - **Reason:** Removing the last element (or any other non-matching element) will make the array not beautiful.

3. **Test Case 3:**
   - **Input:** `6 1 2 1 2 1 2`
   - **Expected Output:** `1`
   - **Reason:** Removing any single element will make the array not beautiful.

4. **Test Case 4:**
   - **Input:** `7 3 3 3 5 3 3 3`
   - **Expected Output:** `3`
   - **Reason:** Removing the first three elements (or any other set of three elements) will make the array not beautiful.

This test input is designed to cover various edge cases and should help in exposing any bugs in the provided code.