## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Remove Prefix Codeforces Solution

B. Remove Prefix
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp was presented with some sequence of integers $a$ of length $n$ ($1\le {a}_{i}\le n$). A sequence can make Polycarp happy only if it consists of different numbers (i.e. distinct numbers).

In order to make his sequence like this, Polycarp is going to make some (possibly zero) number of moves.

In one move, he can:

Solution Click Below:-  👉

👇👇👇👇👇

occupied

• remove the first (leftmost) element of the sequence.

For example, in one move, the sequence $\left[3,1,4,3\right]$ will produce the sequence $\left[1,4,3\right]$, which consists of different numbers.

Determine the minimum number of moves he needs to make so that in the remaining sequence all elements are different. In other words, find the length of the smallest prefix of the given sequence $a$, after removing which all values in the sequence will be unique.

Input

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

Each test case consists of two lines.

The first line contains an integer $n$ ($1\le n\le 2\cdot {10}^{5}$) — the length of the given sequence $a$.

The second line contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le n$) — elements of the given sequence $a$.

It is guaranteed that the sum of $n$ values over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case print your answer on a separate line — the minimum number of elements that must be removed from the beginning of the sequence so that all remaining elements are different.