You need to change this grouping so all components in it are equivalent (I. e. it contains a few events of a similar component). To accomplish this, you pick some integer x that happens to some extent once in a, and afterward play out the accompanying activity quite a few times (perhaps zero): pick some portion [l,r] of the arrangement and eliminate it. Yet, there is one special case: you are not permitted to pick a fragment that contains
Correct answer will be upvoted else Multiple Downvoted. Computer science.
You need to change this grouping so all components in it are equivalent (I. e. it contains a few events of a similar component).
To accomplish this, you pick some integer x that happens to some extent once in a, and afterward play out the accompanying activity quite a few times (perhaps zero): pick some portion [l,r] of the arrangement and eliminate it. Yet, there is one special case: you are not permitted to pick a fragment that contains x. All the more officially, you pick some adjoining aftereffect [al,al+1,… ,ar] to such an extent that ai≠x if l≤i≤r, and eliminate it. After expulsion, the numbering of components to one side of the eliminated portion changes: the component that was the (r+1)- th is presently l-th, the component that was (r+2)- th is currently (l+1)- th, etc (I. e. the leftover arrangement simply falls).
Note that you can not change x after you picked it.
For instance, assume n=6, a=[1,3,2,4,1,2]. Then, at that point, one of the ways of changing it in two activities is to pick x=1, then, at that point:
pick l=2, r=4, so the subsequent grouping is a=[1,1,2];
pick l=3, r=3, so the subsequent grouping is a=[1,1].
Note that picking x isn't an activity. Additionally, note that you can not eliminate any event of x.
Your assignment is to observe the base number of activities needed to change the succession in a manner depicted previously.
You need to answer t free experiments.
Input
The primary line of the input contains one integer t (1≤t≤2⋅104) — the number of experiments. Then, at that point, t experiments follow.
The primary line of the experiment contains one integer n (1≤n≤2⋅105) — the number of components in a. The second line of the experiment contains n integers a1,a2,… ,an (1≤ai≤n), where
It is ensured that the amount of n doesn't surpass 2⋅105 (∑n≤2⋅105).
Output
For each experiment, print the appropriate response — the base number of tasks needed to change the given succession in a manner portrayed in the issue explanation. It very well may be demonstrated that it is consistently conceivable to play out a limited succession of activities so the arrangement is changed in the necessary manner.
Step by step
Solved in 4 steps with 1 images