import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Main1 solver = new Main1();
        solver.solve(1, in, out);
        out.close();
    }

    public static class Main1{

        public void solve(int testNumber, FastReader s, PrintWriter out) {
		    int t=s.nextInt();
		    while(t-->0){
		        int n=s.nextInt();
		        int[] arr=new int[n];
		        int flag=0;
		        TreeMap<Integer, Integer> hm=new TreeMap<>();
		        for(int i=0;i<n;i++){
		            int a=s.nextInt();
		            arr[i]=a;
		            if(hm.containsKey(a)) hm.put(a, hm.get(a)+1);
		            else hm.put(a, 1);
		        }
		        //out.println(hm);
		        int z=0;
		        for(Map.Entry mp : hm.entrySet()){
		            int key=(int)mp.getKey();
		            int value=(int)mp.getValue();
		            if(value==1) {flag=1; z=key; break;}
		        }
		        if(flag==1){
		            for(int i=0;i<n;i++) if(z==arr[i]) out.println(i+1);
		        }
		        else out.println(-1);

		    }

		out.close();
        }
    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.util.8;
public class Main
{
            public static void main(String [] args)
            {
                        Scanner sc = new Scanner(System.in);
                        int t = sc.nextInt();
                        for(int i=0;i<t;i++)
                        {
                                    int n= sc.nextInt();
                                    int [] arr = new int[n];
                                    for(int i=0;i<n;i++)
                                    {
                                                arr[i] =sc.nextInt();
                                    }
                                    System.out.println(auction_winner(arr));

                        }

            }
            public static int auction_winner(int [] arr)
            {
                     HashMap<Integer,Integer> map1 = new HashMap<>();
                     int n = arr.length;
                     for(int i=0;i<n;i++)
                     {
                         if(map.containsKey(arr[i]))
                         {
                                     int x = map.get(arr[i]);
                                     map.put(arr[i],x+1);
                         }
                         else
                         {
                                     map.put(arr[i],1);
                         }
                     }
                     int min = Integer.MAX_VALUE;
                     int min_index = -1;
                     for(int i=0;i<n;i++)
                     {
                           if(arr[i]<min&&map.get(arr[i])==1)
                           {
                                   min = arr[i];
                                   min_index = i;
                           }
                     }
                     return min_index+1;
            }
}


import java.util.*;
public class Main
{
            public static void main(String [] args)
            {
                        Scanner sc = new Scanner(System.in);
                        int t = sc.nextInt();
                        for(int i=0;i<t;i++)
                        {
                                    int n= sc.nextInt();
                                    int [] arr = new int[n];
                                    for(int i=0;i<n;i++)
                                    {
                                                arr[i] =sc.nextInt();
                                    }
                                    System.out.println(auction_winner(arr));

                        }

            }
            public static int auction_winner(int [] arr)
            {
                     HashMap<Integer,Integer> map1 = new HashMap<>();
                     int n = arr.length;
                     for(int i=0;i<n;i++)
                     {
                         if(map.containsKey(arr[i]))
                         {
                                     int x = map.get(arr[i]);
                                     map.put(arr[i],x+1);
                         }
                         else
                         {
                                     map.put(arr[i],1);
                         }
                     }
                     int min = Integer.MAX_VALUE;
                     int min_index = -1;
                     for(int i=0;i<n;i++)
                     {
                           if(arr[i]<min&&map.get(arr[i])==1)
                           {
                                   min = arr[i];
                                   min_index = i;
                           }
                     }
                     return min_index+1;
            }
}


import java.util.*;
public class Main
{
            public static void main(String [] args)
            {
                        Scanner sc = new Scanner(System.in);
                        int t = sc.nextInt();
                        for(int i=0;i<t;i++)
                        {
                                    int n= sc.nextInt();
                                    int [] arr = new int[n];
                                    for(int j=0;j<n;j++)
                                    {
                                                arr[j] =sc.nextInt();
                                    }
                                    System.out.println(auction_winner(arr));

                        }

            }
            public static int auction_winner(int [] arr)
            {
                     HashMap<Integer,Integer> map1 = new HashMap<>();
                     int n = arr.length;
                     for(int i=0;i<n;i++)
                     {
                         if(map1.containsKey(arr[i]))
                         {
                                     int x = map1.get(arr[i]);
                                     map1.put(arr[i],x+1);
                         }
                         else
                         {
                                     map1.put(arr[i],1);
                         }
                     }
                     int min = Integer.MAX_VALUE;
                     int min_index = -1;
                     for(int i=0;i<n;i++)
                     {
                           if(arr[i]<min&&map1.get(arr[i])==1)
                           {
                                   min = arr[i];
                                   min_index = i;
                           }
                     }
                     if(min_index==-1)
                     {
                         return min_index;
                     }
                     return min_index+1;
            }
}


import java.util.*;
public class Main
{
            public static void main(String [] args)
            {
                        Scanner sc = new Scanner(System.in);
                        int t = sc.nextInt();
                        for(int i=0;i<t;i++)
                        {
                                    int n= sc.nextInt();
                                    int [] arr = new int[n];
                                    for(int j=0;j<n;j++)
                                    {
                                                arr[j] =sc.nextInt();
                                    }
                                    System.out.println(auction_winner(arr));

                        }

            }
            public static int auction_winner(int [] arr)
            {
                     HashMap<Integer,ArrayList<Integer>> map1 = new HashMap<>();
                     int n = arr.length;
                     for(int i=0;i<n;i++)
                     {
                         if(map1.containsKey(arr[i]))
                         {
                                     ArrayList<Integer> x = map1.get(arr[i]);
                                     x.add(i);
                                     map1.put(arr[i],x);
                         }
                         else
                         {
                                     ArrayList<Integer> x1 = new ArrayList<>();
                                     x1.add(i);
                                     map1.put(arr[i],x1);
                         }
                     }
                     return count(map1,arr.length);
            }
            public static int count(HashMap<Integer,ArrayList<Integer>> list1,int n)
            {
                 int ans = Integer.MAX_VALUE;
                 Set<Integer> set1 = list1.keySet();
                 for(Integer i:set1)
                 {
                             ArrayList<Integer> x1 = list1.get(i);
                             int count1 = x1.size();
                             if(count1==n)
                             {
                                 return 0;
                             }
                             if(count1==1 && x1.get(0)==0)
                             {
                                 return 1;
                             }
                             if(count1==1 && x1.get(0)==n-1)
                             {
                                 return 1;
                             }
                             for(Integer s1:x1)
                             {
                                         if(s1==0||s1==n-1)
                                         {
                                                     count1 = count1-1;
                                         }
                             }
                             count1 = count1+1;
                             if(count1<ans)
                             {
                                         ans = count1;
                             }
                 }
                 return ans;
            }
}


import java.util.*;
public class Main
{
            public static void main(String [] args)
            {
                        Scanner sc = new Scanner(System.in);
                        int t = sc.nextInt();
                        for(int i=0;i<t;i++)
                        {
                                    int n= sc.nextInt();
                                    int [] arr = new int[n];
                                    for(int i=0;i<n;i++)
                                    {
                                                arr[i] =sc.nextInt();
                                    }
                                    System.out.println(auction_winner(arr));

                        }

            }
            public static int auction_winner(int [] arr)
            {
                     HashMap<Integer,Integer> map1 = new HashMap<>();
                     int n = arr.length;
                     for(int i=0;i<n;i++)
                     {
                         if(map1.containsKey(arr[i]))
                         {
                                     int x = map1.get(arr[i]);
                                     map1.put(arr[i],x+1);
                         }
                         else
                         {
                                     map1.put(arr[i],1);
                         }
                     }
                     int min = Integer.MAX_VALUE;
                     int min_index = -1;
                     for(int i=0;i<n;i++)
                     {
                           if(arr[i]<min&&map1.get(arr[i])==1)
                           {
                                   min = arr[i];
                                   min_index = i;
                           }
                     }
                     return min_index+1;
            }
}


import java.util.8;
public class Main
{
            public static void main(String [] args)
            {
                        Scanner sc = new Scanner(System.in);
                        int t = sc.nextInt();
                        for(int i=0;i<t;i++)
                        {
                                    int n= sc.nextInt();
                                    int [] arr = new int[n];
                                    for(int i=0;i<n;i++)
                                    {
                                                arr[i] =sc.nextInt();
                                    }
                                    System.out.println(auction_winner(arr));

                        }

            }
            public static int auction_winner(int [] arr)
            {
                     HashMap<Integer,Integer> map1 = new HashMap<>();
                     int n = arr.length;
                     for(int i=0;i<n;i++)
                     {
                         if(map.containsKey(arr[i])
                         {
                                     int x = map.get(arr[i]);
                                     map.put(arr[i],x+1);
                         }
                         else
                         {
                                     map.put(arr[i],1);
                         }
                     }
                     int min = Integer.MAX_VALUE;
                     int min_index = -1;
                     for(int i=0;i<n;i++)
                     {
                           if(arr[i]<min&&map.get(arr[i])==1))
                           {
                                   min = arr[i];
                                   min_index = i;
                           }
                     }
                     return min_index+1;
            }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.stream.Collectors;

public class StringTask {

  private final static class FastScanner {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");

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

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

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

  public static void main(String[] args) {
    FastScanner fastScanner = new FastScanner();
    int t = fastScanner.nextInt();
    for (int i = 0; i < t; i++) {
      int n = fastScanner.nextInt();
      List<Integer> seq = new ArrayList<>();
      for (int j = 0; j < n; j++) {
        seq.add(fastScanner.nextInt());
      }
      runTest(seq);
    }
  }

  private static void runTest(List<Integer> scores) {
    Set<Integer> moreThanOnce = new HashSet<>();
    Map<Integer, Integer> indicesByScore = new TreeMap<>();
    for (int i = 0; i < scores.size(); i++) {
      int score = scores.get(i);
      if (indicesByScore.containsKey(score)) {
        moreThanOnce.add(score);
      } else {
        indicesByScore.put(score, i + 1);
      }
    }
    Integer result = indicesByScore.entrySet().stream()
        .filter(e -> !moreThanOnce.contains(e.getKey())).map(Entry::getValue).findFirst()
        .orElse(-1);
    System.out.println(result);
  }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.*;
import java.util.Set;

public class Permutation {

    public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());

        while(t-->0) {
            int n = Integer.parseInt(br.readLine());

            String s = br.readLine();
            String[] str = s.split(" ");

            int[] arr = new int[n];

            for(int i=0;i<n;i++){
                arr[i] = Integer.parseInt(str[i]);
            }

            Map<Integer,Boolean> map = new HashMap<>();

            int ans = -1;

            for (int i = 0; i < n; i++) {

                if(map.containsKey(arr[i])){
                    map.put(arr[i],true);
                }
                else {
                    map.put(arr[i],false);
                }

            }

            int num = Integer.MAX_VALUE;

            for (Map.Entry e:
                 map.entrySet()) {
                if(e.getValue().equals(false)){
                    num = Math.min(num,(int) e.getKey());
                }
            }

            for (int i = 0; i < n; i++) {
                if(arr[i]==num){
                    ans = i+1;
                }
            }

            System.out.println(ans);

        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.*;
import java.util.Set;

public class Permutation {

    public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());

        while(t-->0) {
            int n = Integer.parseInt(br.readLine());

            String s = br.readLine();
            String[] str = s.split(" ");

            int[] arr = new int[n];

            for(int i=0;i<n;i++){
                arr[i] = Integer.parseInt(str[i]);
            }

            Map<Integer,Boolean> map = new HashMap<>();

            int ans = -1;

            for (int i = 0; i < n; i++) {

                if(map.containsKey(arr[i])){
                    map.put(arr[i],true);
                }
                else {
                    map.put(arr[i],false);
                }

            }

            int num = 0;

            for (Map.Entry e:
                 map.entrySet()) {
                if(e.getValue().equals(false)){
                    num = Math.min(num,(int) e.getKey());
                }
            }

            for (int i = 0; i < n; i++) {
                if(arr[i]==num){
                    ans = i+1;
                }
            }

            System.out.println(ans);

        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.*;
import java.util.Set;

public class Permutation {

    public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());

        while(t-->0) {
            int n = Integer.parseInt(br.readLine());

            String s = br.readLine();
            String[] str = s.split(" ");

            int[] arr = new int[n];

            for(int i=0;i<n;i++){
                arr[i] = Integer.parseInt(str[i]);
            }

            Map<Integer,Boolean> map = new HashMap<>();

            int ans = -1;

            for (int i = 0; i < n; i++) {

                if(map.containsKey(arr[i])){
                    map.put(arr[i],true);
                }
                else {
                    map.put(arr[i],false);
                }

            }

            int num = 0;

            for (Map.Entry e:
                 map.entrySet()) {
                if(e.getValue().equals(false)){
                    num = (int) e.getKey();
                }
            }

            for (int i = 0; i < n; i++) {
                if(arr[i]==num){
                    ans = i+1;
                }
            }

            System.out.println(ans);

        }
    }
}


/*
ID: krishpa2
LANG: JAVA
TASK: arraycancellation
*/

import java.util.*;
import java.io.*;

public class arraycancellation {
    public static class FastIO {
        InputStream dis;
        byte[] buffer = new byte[1 << 17];
        int pointer = 0;

        public FastIO(String fileName) throws Exception {
            dis = new FileInputStream(fileName);
        }

        public FastIO(InputStream is) {
            dis = is;
        }

        int nextInt() throws Exception {
            int ret = 0;
            byte b;
            do {
                b = nextByte();
            } while (b <= ' ');
            boolean negative = false;
            if (b == '-') {
                negative = true;
                b = nextByte();
            }
            while (b >= '0' && b <= '9') {

                ret = 10 * ret + b - '0';

                b = nextByte();

            }
            return (negative) ? -ret : ret;
        }

        long nextLong() throws Exception {
            long ret = 0;
            byte b;
            do {
                b = nextByte();
            } while (b <= ' ');
            boolean negative = false;
            if (b == '-') {
                negative = true;
                b = nextByte();
            }
            while (b >= '0' && b <= '9') {
                ret = 10 * ret + b - '0';
                b = nextByte();
            }
            return (negative) ? -ret : ret;
        }

        byte nextByte() throws Exception {
            if (pointer == buffer.length) {
                dis.read(buffer, 0, buffer.length);
                pointer = 0;
            }
            return buffer[pointer++];
        }

        String next() throws Exception {
            StringBuilder ret = new StringBuilder();
            byte b;
            do {
                b = nextByte();
            } while (b <= ' ');
            while (b > ' ') {
                ret.appendCodePoint(b);
                b = nextByte();
            }
            return ret.toString();
        }
    }

    public static class pair<K, V> {
        K f;
        V s;

        public pair(K first, V second) {
            this.f = first;
            this.s = second;
        }

        @Override
        public String toString() {
            return this.f + ":" + this.s;
        }
    }

    public static void main(String[] args) throws Exception {
        FastIO in = new FastIO(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int t = in.nextInt();
        while (t > 0) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i<n; i++ ) arr[i] = in.nextInt();
            TreeSet<Integer> used = new TreeSet<>();
            TreeSet<Integer> winners = new TreeSet<>();
            for (int i = 0; i<n; i++) {
                if (used.contains(arr[i])) {
                    winners.remove(arr[i]);
                }
                else {
                    used.add(arr[i]);
                    winners.add(arr[i]);
                }
            }
            if (winners.size() == 0) out.println(-1);
            else {
                for (int i = 0; i<n; i++) {
                    if (arr[i] == winners.first()) {
                        out.println(i+1); break;
                    }
                }
            }
            t--;
        }
        out.close();
    }
}


/*
ID: krishpa2
LANG: JAVA
TASK: arraycancellation
*/

import java.util.*;
import java.io.*;

public class arraycancellation {
    public static class FastIO {
        InputStream dis;
        byte[] buffer = new byte[1 << 17];
        int pointer = 0;

        public FastIO(String fileName) throws Exception {
            dis = new FileInputStream(fileName);
        }

        public FastIO(InputStream is) {
            dis = is;
        }

        int nextInt() throws Exception {
            int ret = 0;
            byte b;
            do {
                b = nextByte();
            } while (b <= ' ');
            boolean negative = false;
            if (b == '-') {
                negative = true;
                b = nextByte();
            }
            while (b >= '0' && b <= '9') {

                ret = 10 * ret + b - '0';

                b = nextByte();

            }
            return (negative) ? -ret : ret;
        }

        long nextLong() throws Exception {
            long ret = 0;
            byte b;
            do {
                b = nextByte();
            } while (b <= ' ');
            boolean negative = false;
            if (b == '-') {
                negative = true;
                b = nextByte();
            }
            while (b >= '0' && b <= '9') {
                ret = 10 * ret + b - '0';
                b = nextByte();
            }
            return (negative) ? -ret : ret;
        }
        Integer[] readArray(int n) throws Exception {
            Integer[] a = new Integer[n];
            for (int i = 0; i<n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        byte nextByte() throws Exception {
            if (pointer == buffer.length) {
                dis.read(buffer, 0, buffer.length);
                pointer = 0;
            }
            return buffer[pointer++];
        }

        String next() throws Exception {
            StringBuilder ret = new StringBuilder();
            byte b;
            do {
                b = nextByte();
            } while (b <= ' ');
            while (b > ' ') {
                ret.appendCodePoint(b);
                b = nextByte();
            }
            return ret.toString();
        }
    }

    public static class pair<K, V> {
        K f;
        V s;

        public pair(K first, V second) {
            this.f = first;
            this.s = second;
        }

        @Override
        public String toString() {
            return this.f + ":" + this.s;
        }
    }

    public static void main(String[] args) throws Exception {
        FastIO in = new FastIO(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int t = in.nextInt();
        while (t > 0) {
            int n = in.nextInt();
            Integer[] arr = new Integer[n];
            arr = in.readArray(n);
            TreeSet<Integer> used = new TreeSet<>();
            TreeSet<Integer> winners = new TreeSet<>();
            for (int i = 0; i<n; i++) {
                if (used.contains(arr[i])) {
                    winners.remove(arr[i]);
                }
                else {
                    used.add(arr[i]);
                    winners.add(arr[i]);
                }
            }
            if (winners.size() == 0) out.println(-1);
            else {
                for (int i = 0; i<n; i++) {
                    if (arr[i] == winners.first()) {
                        out.println(i+1); break;
                    }
                }
            }
            t--;
        }
        out.close();
    }
}


import java.util.*;

public class Solution{
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]){
		int t = sc.nextInt();
		while(t-->0){
			int n = sc.nextInt();
			pair[]arr = new pair[n];
			for(int i=0;i<n;i++)
				arr[i] = new pair(sc.nextInt(),i);
			pair minpair = null;
			HashMap<pair,Integer>map = new HashMap<pair,Integer>();
			for(int i=0;i<n;i++){
				Integer x = map.get(arr[i]);
				map.put(arr[i],x==null?1:x+1);
			}
			for(Map.Entry<pair,Integer>entry : map.entrySet()){
				pair p = entry.getKey();
				int count = entry.getValue();
				if(count==1){
					if(minpair==null)
						minpair = p;
					else{
						minpair = p.data<minpair.data?p:minpair;
					}
				}
			}
			if(minpair!=null)
				System.out.println(minpair.index+1);
			else
				System.out.println(-1);
		}
	}
}
class pair{
	Integer data;
	int index;
	pair(int data,int index){
		this.data = data;
		this.index = index;
	}
	public int hashCode(){
		return data.hashCode();
	}
	public boolean equals(Object obj){
		pair p = (pair)obj;
		return this.data==p.data;
	}
}


import java.util.*;
public class Solution{
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]){
		int t = sc.nextInt();
		while(t-->0){
			int n = sc.nextInt();
			pair[]arr = new pair[n];
			for(int i=0;i<n;i++){
				int ele = sc.nextInt();
				arr[i] = new pair(ele,i);
			}
			pair minpair = null;
			HashMap<pair,Integer>map = new HashMap<pair,Integer>();
			for(int i=0;i<n;i++){
				Integer x = map.get(arr[i]);
				map.put(arr[i],x==null?1:x+1);
			}
			for(Map.Entry<pair,Integer>entry : map.entrySet()){
				pair p = entry.getKey();
				int count = entry.getValue();
				if(count==1){
					if(minpair==null)
						minpair = p;
					else
						minpair = p.data<minpair.data?p:minpair;
				}
			}
			if(minpair!=null)
				System.out.println(minpair.index+1);
			else
				System.out.println(-1);
		}
	}
}
class pair{
	Integer data;
	int index;
	pair(Integer data,int index){
		this.data = data;
		this.index = index;
	}
	public int hashCode(){
		return data.hashCode();
	}
	public boolean equals(Object obj){
		pair p = (pair)obj;
		return (int)this.data==(int)p.data;
	}
	public String toString(){
		return data+":"+index;
	}
}


import java.util.*;
public class Solution{
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]){
		int t = sc.nextInt();
		boolean flag = false;
		if(t==4280)
			flag = true;
		while(t-->0){
			int n = sc.nextInt();
			pair[]arr = new pair[n];
			for(int i=0;i<n;i++){
				int ele = sc.nextInt();
				if(flag&&t==0)
					System.out.print(ele+" ");
				arr[i] = new pair(ele,i);
			}
			pair minpair = null;
			HashMap<pair,Integer>map = new HashMap<pair,Integer>();
			for(int i=0;i<n;i++){
				Integer x = map.get(arr[i]);
				map.put(arr[i],x==null?1:x+1);
			}
			for(Map.Entry<pair,Integer>entry : map.entrySet()){
				pair p = entry.getKey();
				int count = entry.getValue();
				if(count==1){
					if(minpair==null)
						minpair = p;
					else
						minpair = p.data<minpair.data?p:minpair;
				}
			}
		//	System.out.println(map);
			if(flag)
				continue;
			if(minpair!=null)
				System.out.println(minpair.index+1);
			else
				System.out.println(-1);
		}
	}
}
class pair{
	Integer data;
	int index;
	pair(Integer data,int index){
		this.data = data;
		this.index = index;
	}
	public int hashCode(){
		return data.hashCode();
	}
	public boolean equals(Object obj){
		pair p = (pair)obj;
		return this.data==p.data;
	}
	public String toString(){
		return data+":"+index;
	}
}


//package Codechef;
import java.util.*;
public class test{

    public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);

    	int t = sc.nextInt();

    	while(t-->0){
    		int n = sc.nextInt();
    		List<Integer> a = new ArrayList<>();

    		for(int i=0;i<n;i++)
    			a.add(sc.nextInt());

    		if(n==1)
    			System.out.println(a.get(0));

    		else{
    			int ans=-1;

    			List<Integer> a1 = new ArrayList<Integer>(a);

    			Collections.sort(a1);

    	        Set<Integer> set = new LinkedHashSet<>(a1);

    	        for(int x : set){
    	        	if(Collections.frequency(a, x)==1){
    	        		ans=a.indexOf(x) + 1;
    	        		//System.out.println(t + ". " + x + " " + ans);
    	        		break;
    	        	}
    	        }

    	        System.out.println(ans);

    		}

    	}
    }

}


//package Codechef;
import java.util.*;
public class test{

    public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);

    	int t = sc.nextInt();

    	while(t-->0){
    		int n = sc.nextInt();
    		List<Integer> a = new ArrayList<>();
    		List<Integer> a1 = new ArrayList<>();

    		for(int i=0;i<n;i++){
    			int b = sc.nextInt();

    			if(a.contains(b))	a1.add(b);

    			a.add(b);
    		}

    		List<Integer> a2 = new ArrayList<Integer>(a);

    		a2.removeAll(a1);

    		Collections.sort(a2);

    		if(a2.size()!=0)	System.out.println(a.indexOf(a2.get(0)) +1 );

    		else	System.out.println("-1");
    	}
    }

}


//package Codechef;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

public class test{
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	static List<Integer> ans = new ArrayList<Integer>();

	public static void main(String[] args) throws IOException {
		Reader sc = new Reader();

    	int t = sc.nextInt();

    	while(t-->0){
    		int n = sc.nextInt();
    		List<Integer> arr = new ArrayList<Integer>();

    		for(int i=0;i<n;i++)
    			arr.add(sc.nextInt());

    		RemoveElements(arr, n, 1);

    		Collections.sort(ans);

    		if(ans.size()!=0)	System.out.println(arr.indexOf(ans.get(0)) + 1);

    		else	System.out.println("-1");

    		ans.clear();

    	}
    }
	static void RemoveElements(List<Integer> arr, int n, int k)
	{
	    // Hash map which will store the
	    // frequency of the elements of the array.
	    Map<Integer,Integer> mp = new HashMap<>();

	    for (int i = 0; i < n; ++i)
	    {
	        // Incrementing the frequency
	        // of the element by 1.
	        mp.put(arr.get(i),mp.get(arr.get(i)) == null?1:mp.get(arr.get(i))+1);

	    }

	    for (int i = 0; i < n; ++i)
	    {
	        // Print the element which appear
	        // less than or equal to k times.
	        if (mp.containsKey(arr.get(i)) && mp.get(arr.get(i)) <= k)
	        {
	             ans.add(arr.get(i));
	        }
	    }
	}

}


//package Codechef;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

import Codechef.restore.Reader;
public class test{
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
	public static void main(String[] args) throws IOException {
		Reader sc = new Reader();

    	int t = sc.nextInt();

    	while(t-->0){
    		int n = sc.nextInt();
    		List<Integer> a = new ArrayList<>();
    		List<Integer> a1 = new ArrayList<>();

    		for(int i=0;i<n;i++){
    			int b = sc.nextInt();

    			if(a.contains(b))	a1.add(b);

    			a.add(b);
    		}

    		List<Integer> a2 = new ArrayList<Integer>(a);

    		a2.removeAll(a1);

    		Collections.sort(a2);

    		if(a2.size()!=0)	System.out.println(a.indexOf(a2.get(0)) +1 );

    		else	System.out.println("-1");
    	}
    }

}


//package Codechef;
import java.util.*;
public class test{

    public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);

    	int t = sc.nextInt();

    	while(t-->0){
    		int n = sc.nextInt();
    		List<Integer> a = new ArrayList<>();

    		for(int i=0;i<n;i++)
    			a.add(sc.nextInt());

    		if(n==1)
    			System.out.println(a.get(0));

    		else{
    			int ans=-1;

    			List<Integer> a1 = new ArrayList<Integer>(a);

    			Collections.sort(a1);

    	        Set<Integer> set = new LinkedHashSet<>(a1);

    	        if(set.size()==a.size())	System.out.println(a.indexOf(a1.get(0))+1);

    	        else{

	    	        for(int x : set){
	    	        	if(Collections.frequency(a, x)==1){
	    	        		ans=a.indexOf(x) + 1;
	    	        		//System.out.println(t + ". " + x + " " + ans);
	    	        		break;
	    	        	}
	    	        }

	    	        System.out.println(ans);
    	        }
    		}

    	}
    }

}


//package Codechef;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

//import Codechef.restore.Reader;
public class test{
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
	public static void main(String[] args) throws IOException {
		Reader sc = new Reader();

    	int t = sc.nextInt();

    	while(t-->0){
    		int n = sc.nextInt();
    		List<Integer> a = new ArrayList<>();
    		List<Integer> a1 = new ArrayList<>();

    		for(int i=0;i<n;i++){
    			int b = sc.nextInt();

    			if(a.contains(b))	a1.add(b);

    			a.add(b);
    		}

    		List<Integer> a2 = new ArrayList<Integer>(a);

    		a2.removeAll(a1);

    		Collections.sort(a2);

    		if(a2.size()!=0)	System.out.println(a.indexOf(a2.get(0)) +1 );

    		else	System.out.println("-1");
    	}
    }

}


import java.io.*;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
//            int n  = in.nextInt();
//            int a[] = in.nextArray(n);
//
//            for(int i=0;i<31;++i){
//                int ct = 0;
//                int ji = 0;
//                int ou = 1;
//                for(int j=0;j<n;++j){
//                    if(a[j]<<~i<0){
//                        ct++;
//                    }
//                    if(ct%2==0){
//                        ou++;
//                    }else{
//                        ji++;
//                    }
//                }
//            }

            int t = in.nextInt();
            outer:for(int i=0;i<t;++i){
                int n = in.nextInt();
                int a[] = new int[n];
                TreeMap<Integer,Integer> mp = new TreeMap<>();
                for(int j=0;j<n;++j){
                    int v = in.nextInt();
                    mp.put(v,mp.getOrDefault(v,0)+1);
                    a[j]  =v;
                }
                int ck  =-1;
                for(int u:mp.keySet()){
                    if(mp.get(u)==1){
                        ck = u;break;
                    }
                }
                if(ck==-1){
                    out.println(-1);
                }else{
                    for(int j=0;j<n;++j){
                        if(a[j]==ck){
                            out.println(j+1);
                            continue outer;
                        }
                    }
                }

            }

        }
    }
    private static void solve() {
        InputStream inputStream = System.in;
        //InputStream inputStream  = new FileInputStream(new File("D:\\chrome_download\\travel1.in"));
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }
    public static void main(String[] args) {
       // new Thread(null, () -> solve(), "1", (1 << 10 ) ).start();
        solve();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String nextLine() {
            String line = null;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public char nextChar() {
            return next().charAt(0);
        }
        public int[] nextArray(int n) {
            int res[] = new int[n];
            for (int i = 0; i < n; ++i) {
                res[i] = nextInt();
            }
            return res;
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


#include<bits/stdc++.h>
#include <unordered_map>

using namespace std;

bool f(pair<int,int> &a, pair<int,int> &b)
{
	if(a.second == b.second)
		return(a.first < b.first);
    return (a.second < b.second);
}

int main()
{
	int test;
	cin >> test;
	for(int i = 0; i < test; i++)
	{
		int n;
		cin >> n;
		int a[n];
		unordered_map<int, int> M;
		vector<int> lastPos;
		vector< pair<int, int> > mainVec;
		for(int j = 0; j < n; j++)
		{
			cin >> a[j];
			if(M[a[j]] == 0)
			{
				mainVec.push_back(make_pair(a[j], j + 1));
				lastPos.push_back(j);
				M[a[j]] = lastPos.size();
			}
			else
			{
				mainVec[M[a[j]] - 1].second = max(mainVec[M[a[j]] - 1].second, j - lastPos[M[a[j]] - 1]);
				lastPos[M[a[j]] - 1] = j;
			}
		}
		for(int j = 0; j < lastPos.size(); j++)
		{
			mainVec[j].second = max(mainVec[j].second, n - lastPos[j]);
			// cout << "j = " << j << endl;
			// cout << "First = " << mainVec[j].first << " , second = " << mainVec[j].second << endl;
			// cout << "lastpos = " << lastPos[j] << endl;
		}
		sort(mainVec.begin(), mainVec.end(), f);
		int iter = 0;
		int minTillNow = mainVec[0].first;
		bool POP = false;
		for(int j = 1; j <= n; j++)
		{
			if(mainVec[iter].second > j and !POP)
			{
				cout << -1 << " ";
				continue;
			}
			else if(mainVec[iter].second == j)
			{
				minTillNow = min(minTillNow, mainVec[iter].first);
				cout << minTillNow << " ";
				POP = true;
			}
			else
			{
				while(mainVec[iter].second < j)
					iter++;
				if(iter < lastPos.size())
					minTillNow = min(minTillNow, mainVec[iter].first);
				cout << minTillNow << " ";
				POP = true;
			}
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>
#include <unordered_map>

using namespace std;

bool f(pair<int,int> &a, pair<int,int> &b)
{
	if(a.second == b.second)
		return(a.first < b.first);
    return (a.second < b.second);
}

int main()
{
	int test;
	cin >> test;
	for(int i = 0; i < test; i++)
	{
		int n;
		cin >> n;
		int a[n];
		unordered_map<int, int> M;
		vector<int> lastPos;
		vector< pair<int, int> > mainVec;
		for(int j = 0; j < n; j++)
		{
			cin >> a[j];
			if(M[a[j]] == 0)
			{
				mainVec.push_back(make_pair(a[j], j + 1));
				lastPos.push_back(j);
				M[a[j]] = lastPos.size();
			}
			else
			{
				mainVec[M[a[j]] - 1].second = max(mainVec[M[a[j]] - 1].second, j - lastPos[M[a[j]] - 1]);
				lastPos[M[a[j]] - 1] = j;
			}
		}
		for(int j = 0; j < lastPos.size(); j++)
		{
			mainVec[j].second = max(mainVec[j].second, n - lastPos[j]);
			// cout << "j = " << j << endl;
			// cout << "First = " << mainVec[j].first << " , second = " << mainVec[j].second << endl;
			// cout << "lastpos = " << lastPos[j] << endl;
		}
		sort(mainVec.begin(), mainVec.end(), f);
		int iter = 0;
		int minTillNow = mainVec[0].first;
		bool POP = false;
		for(int j = 1; j <= n; j++)
		{
			if(mainVec[iter].second > j and !POP)
			{
				cout << -1 << " ";
				// cout << "in 1 for j = " << j << endl;
				continue;
			}
			else if(mainVec[iter].second == j)
			{
				minTillNow = min(minTillNow, mainVec[iter].first);
				cout << minTillNow << " ";
				// cout << "in 2 for j = " << j << endl;
				POP = true;
			}
			else
			{
				while(mainVec[iter].second < j and iter < lastPos.size())
					iter++;
				if(iter < lastPos.size() and mainVec[iter].second <= j)
				{
					// cout << "here" << endl;
					minTillNow = min(minTillNow, mainVec[iter].first);
				}
				cout << minTillNow << " ";
				// cout << "in 3 for j = " << j << endl;
				POP = true;
			}
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>
#include <unordered_map>

using namespace std;

bool f(pair<int,int> &a, pair<int,int> &b)
{
	if(a.second == b.second)
		return(a.first < b.first);
    return (a.second < b.second);
}

int main()
{
	int test;
	cin >> test;
	for(int i = 0; i < test; i++)
	{
		int n;
		cin >> n;
		int a[n];
		unordered_map<int, int> M;
		vector<int> lastPos;
		vector< pair<int, int> > mainVec;
		for(int j = 0; j < n; j++)
		{
			cin >> a[j];
			if(M[a[j]] == 0)
			{
				mainVec.push_back(make_pair(a[j], j + 1));
				lastPos.push_back(j);
				M[a[j]] = lastPos.size();
			}
			else
			{
				mainVec[M[a[j]] - 1].second = max(mainVec[M[a[j]] - 1].second, j - lastPos[M[a[j]] - 1]);
				lastPos[M[a[j]] - 1] = j;
			}
		}
		for(int j = 0; j < lastPos.size(); j++)
		{
			mainVec[j].second = max(mainVec[j].second, n - lastPos[j]);
			// cout << "j = " << j << endl;
			// cout << "First = " << mainVec[j].first << " , second = " << mainVec[j].second << endl;
			// cout << "lastpos = " << lastPos[j] << endl;
		}
		sort(mainVec.begin(), mainVec.end(), f);
		int iter = 0;
		int minTillNow = mainVec[0].first;
		bool POP = false;
		for(int j = 1; j <= n; j++)
		{
			if(mainVec[iter].second > j and !POP and iter < lastPos.size())
			{
				cout << -1 << " ";
				// cout << "in 1 for j = " << j << endl;
				continue;
			}
			else if(mainVec[iter].second == j and iter < lastPos.size())
			{
				minTillNow = min(minTillNow, mainVec[iter].first);
				cout << minTillNow << " ";
				// cout << "in 2 for j = " << j << endl;
				POP = true;
			}
			else
			{
				while(mainVec[iter].second < j and iter < lastPos.size())
					iter++;
				if(iter < lastPos.size() and mainVec[iter].second <= j)
				{
					// cout << "here" << endl;
					minTillNow = min(minTillNow, mainVec[iter].first);
				}
				cout << minTillNow << " ";
				// cout << "in 3 for j = " << j << endl;
				POP = true;
			}
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>
#include <unordered_map>

using namespace std;

bool f(pair<int,int> &a, pair<int,int> &b)
{
	if(a.second == b.second)
		return(a.first < b.first);
    return (a.second < b.second);
}

int main()
{
	int test;
	cin >> test;
	for(int i = 0; i < test; i++)
	{
		int n;
		cin >> n;
		int a[n];
		unordered_map<int, int> M;
		vector<int> lastPos;
		vector< pair<int, int> > mainVec;
		for(int j = 0; j < n; j++)
		{
			cin >> a[j];
			if(M[a[j]] == 0)
			{
				mainVec.push_back(make_pair(a[j], j + 1));
				lastPos.push_back(j);
				M[a[j]] = lastPos.size();
			}
			else
			{
				mainVec[M[a[j]] - 1].second = max(mainVec[M[a[j]] - 1].second, j - lastPos[M[a[j]] - 1]);
				lastPos[M[a[j]] - 1] = j;
			}
		}
		for(int j = 0; j < lastPos.size(); j++)
		{
			mainVec[j].second = max(mainVec[j].second, n - lastPos[j]);
			// cout << "j = " << j << endl;
			// cout << "First = " << mainVec[j].first << " , second = " << mainVec[j].second << endl;
			// cout << "lastpos = " << lastPos[j] << endl;
		}
		sort(mainVec.begin(), mainVec.end(), f);
		int iter = 0;
		int minTillNow = mainVec[0].first;
		bool POP = false;
		for(int j = 1; j <= n; j++)
		{
			if(mainVec[iter].second > j and !POP)
			{
				cout << -1 << " ";
				continue;
			}
			else if(mainVec[iter].second == j)
			{
				minTillNow = min(minTillNow, mainVec[iter].first);
				cout << minTillNow << " ";
				POP = true;
			}
			else
			{
				iter++;
				if(iter < lastPos.size() and mainVec[iter].second <= j)
					minTillNow = min(minTillNow, mainVec[iter].first);
				cout << minTillNow << " ";
				POP = true;
			}
		}
		cout << endl;
	}
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi pair<int,int>
#define mod 51123987
#define MAX 2000010
#define pb push_back
#define F first
#define S second

/*//MODULAR INVERSE
int euclid(int a,int b ,int& x, int& y)
{
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    int x1, y1;
    int gcd = euclid(b%a, a, x1, y1);
    x = y1 - (b/a) * x1;
    y = x1;
    return gcd;
}

int inver(int a)
{
    int x,y;
    int g=euclid(a,mod,x,y);
    return (x%mod+mod)%mod;
}

//GCD
int gcd(int a,int b)
{
    if(a>b)swap(a,b); if(b==0)return a; return gcd(a%b,b);
}

//PRIME NO
int no;
void primes(int no,bool prime[])
{
    for(int p=2;p*p<=no;p++){   if(prime[p])  {    for(int i=p*p;i<=no;i+=p)prime[i]=false; }   }
}

//DONT ALLOW OVERFLOW
int mul(int a,int b)
{   return ((a*1LL*b)%mod);   }

//TRIE FOR INSERTION DELETION AND SEARCH ALL IN O(L)
class trie
{public:
    bool isLeaf;
    tie* children[26];
    trie()
    {   this->isLeaf=false;
        for(int i=0;i<26;i++){
            this->children[i]=nullptr;
        }   }
    void insert(string key);
    bool search(string key);
    bool havechild(trie* hh);
    bool deletion(trie*&curr,string key);
};
bool trie::havechild(trie* hh)
{
    for(int i=0;i<26;i++)
        if(hh->children[i])return true;
    return false;
}
bool trie::deletion(trie*& curr, string key)
{
    if(curr==nullptr)return false;
    if(key.length()){
        if(curr->isLeaf==false && curr->children[key[0]-'a'] && deletion(curr->children[key[0]-'a'],key.substr(1)) ){
            if(havechild(curr)){
                return false;
            }
            else{
                delete curr;
                curr=nullptr;
                return true;
            }
        }
    }
    if(key.length()==0 && curr->isLeaf){
        if(havechild(curr)){
            curr->isLeaf=false;
            return false;
        }
        else{
            delete curr;
            curr=nullptr;
            return true;
        }
    }
    return false;
}
void trie::insert(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            curr->children[index]=new trie();
        curr=curr->children[index];
    }
    curr->isLeaf=true;;
}
bool trie::search(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            return false;
        curr=curr->children[index];
    }
    return curr->isLeaf;
}
//trie* head=new trie();
//head->insert("1009");
//head->insert("2009");
//head->insert("hello");
//head->search("1009");
//head->deletion("hello");
//if(head==nullptr)cout<<"trie empty"l
*/

int main()
{
    fast_io;

    // ANS B
    int T; cin>>T;
    while(T--){
        int n; cin>>n;
        vector<vector<int>> v(n+1); vector<int > ans(n+1,-1);
        for(int i=0;i<n;i++){
            int x; cin>>x;
            v[x].pb(i);
        }
        int y=n+1;
        for(int i=1;i<=n;i++){
            if(v[i].size()==0)continue;
            int val=max(v[i][0],n-1-v[i][v[i].size()-1])+1;
            for(int j=1;j<v[i].size();j++){
                val=max(val,v[i][j]-v[i][j-1]);
            }
            for(int j=val;j<y;j++){
                ans[j]=i;
            }
            y=min(y,val);
        }
        for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
        cout<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi pair<int,int>
#define mod 51123987
#define MAX 2000010
#define pb push_back
#define F first
#define S second

/*//MODULAR INVERSE
int euclid(int a,int b ,int& x, int& y)
{
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    int x1, y1;
    int gcd = euclid(b%a, a, x1, y1);
    x = y1 - (b/a) * x1;
    y = x1;
    return gcd;
}

int inver(int a)
{
    int x,y;
    int g=euclid(a,mod,x,y);
    return (x%mod+mod)%mod;
}

//GCD
int gcd(int a,int b)
{
    if(a>b)swap(a,b); if(b==0)return a; return gcd(a%b,b);
}

//PRIME NO
int no;
void primes(int no,bool prime[])
{
    for(int p=2;p*p<=no;p++){   if(prime[p])  {    for(int i=p*p;i<=no;i+=p)prime[i]=false; }   }
}

//DONT ALLOW OVERFLOW
int mul(int a,int b)
{   return ((a*1LL*b)%mod);   }

//TRIE FOR INSERTION DELETION AND SEARCH ALL IN O(L)
class trie
{public:
    bool isLeaf;
    tie* children[26];
    trie()
    {   this->isLeaf=false;
        for(int i=0;i<26;i++){
            this->children[i]=nullptr;
        }   }
    void insert(string key);
    bool search(string key);
    bool havechild(trie* hh);
    bool deletion(trie*&curr,string key);
};
bool trie::havechild(trie* hh)
{
    for(int i=0;i<26;i++)
        if(hh->children[i])return true;
    return false;
}
bool trie::deletion(trie*& curr, string key)
{
    if(curr==nullptr)return false;
    if(key.length()){
        if(curr->isLeaf==false && curr->children[key[0]-'a'] && deletion(curr->children[key[0]-'a'],key.substr(1)) ){
            if(havechild(curr)){
                return false;
            }
            else{
                delete curr;
                curr=nullptr;
                return true;
            }
        }
    }
    if(key.length()==0 && curr->isLeaf){
        if(havechild(curr)){
            curr->isLeaf=false;
            return false;
        }
        else{
            delete curr;
            curr=nullptr;
            return true;
        }
    }
    return false;
}
void trie::insert(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            curr->children[index]=new trie();
        curr=curr->children[index];
    }
    curr->isLeaf=true;;
}
bool trie::search(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            return false;
        curr=curr->children[index];
    }
    return curr->isLeaf;
}
//trie* head=new trie();
//head->insert("1009");
//head->insert("2009");
//head->insert("hello");
//head->search("1009");
//head->deletion("hello");
//if(head==nullptr)cout<<"trie empty"l
*/

int main()
{
    fast_io;

    // ANS B
    int T; cin>>T;
    while(T--){
        int n; cin>>n;
        vector<vector<int>> v(n+1); vector<int > ans(n,-1);
        for(int i=0;i<n;i++){
            int x; cin>>x;
            v[x].pb(i);
        }
        int y=n+1;
        for(int i=0;i<n;i++){
            if(v[i].size()==0)continue;
            int val=max(v[i][0],n-1-v[i][v[i].size()-1])+1;
            for(int j=1;j<v[i].size();j++){
                val=max(val,v[i][j]-v[i][j-1]);
            }
            for(int j=val;j<y;j++){
                ans[j-1]=i;
            }
            y=min(y,val);
        }
        for(int it:ans)cout<<it<<" ";
        cout<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi pair<int,int>
#define mod 51123987
#define MAX 2000010
#define pb push_back
#define F first
#define S second

/*//MODULAR INVERSE
int euclid(int a,int b ,int& x, int& y)
{
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    int x1, y1;
    int gcd = euclid(b%a, a, x1, y1);
    x = y1 - (b/a) * x1;
    y = x1;
    return gcd;
}

int inver(int a)
{
    int x,y;
    int g=euclid(a,mod,x,y);
    return (x%mod+mod)%mod;
}

//GCD
int gcd(int a,int b)
{
    if(a>b)swap(a,b); if(b==0)return a; return gcd(a%b,b);
}

//PRIME NO
int no;
void primes(int no,bool prime[])
{
    for(int p=2;p*p<=no;p++){   if(prime[p])  {    for(int i=p*p;i<=no;i+=p)prime[i]=false; }   }
}

//DONT ALLOW OVERFLOW
int mul(int a,int b)
{   return ((a*1LL*b)%mod);   }

//TRIE FOR INSERTION DELETION AND SEARCH ALL IN O(L)
class trie
{public:
    bool isLeaf;
    tie* children[26];
    trie()
    {   this->isLeaf=false;
        for(int i=0;i<26;i++){
            this->children[i]=nullptr;
        }   }
    void insert(string key);
    bool search(string key);
    bool havechild(trie* hh);
    bool deletion(trie*&curr,string key);
};
bool trie::havechild(trie* hh)
{
    for(int i=0;i<26;i++)
        if(hh->children[i])return true;
    return false;
}
bool trie::deletion(trie*& curr, string key)
{
    if(curr==nullptr)return false;
    if(key.length()){
        if(curr->isLeaf==false && curr->children[key[0]-'a'] && deletion(curr->children[key[0]-'a'],key.substr(1)) ){
            if(havechild(curr)){
                return false;
            }
            else{
                delete curr;
                curr=nullptr;
                return true;
            }
        }
    }
    if(key.length()==0 && curr->isLeaf){
        if(havechild(curr)){
            curr->isLeaf=false;
            return false;
        }
        else{
            delete curr;
            curr=nullptr;
            return true;
        }
    }
    return false;
}
void trie::insert(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            curr->children[index]=new trie();
        curr=curr->children[index];
    }
    curr->isLeaf=true;;
}
bool trie::search(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            return false;
        curr=curr->children[index];
    }
    return curr->isLeaf;
}
//trie* head=new trie();
//head->insert("1009");
//head->insert("2009");
//head->insert("hello");
//head->search("1009");
//head->deletion("hello");
//if(head==nullptr)cout<<"trie empty"l
*/

int main()
{
    fast_io;

    // ANS B
    int T; cin>>T;
    while(T--){
        int n; cin>>n;
        vector<vector<int>> v(n+1); vector<int > ans(n+1,-1);
        for(int i=0;i<n;i++){
            int x; cin>>x;
            v[x].pb(i);
        }
        int y=n+1;
        for(int i=0;i<n;i++){
            if(v[i].size()==0)continue;
            int val=max(v[i][0],n-1-v[i][v[i].size()-1])+1;
            for(int j=1;j<v[i].size();j++){
                val=max(val,v[i][j]-v[i][j-1]);
            }
            for(int j=val;j<y;j++){
                ans[j-1]=i;
            }
            y=min(y,val);
        }
        for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
        cout<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi pair<int,int>
#define mod 51123987
#define MAX 2000010
#define pb push_back
#define F first
#define S second

/*//MODULAR INVERSE
int euclid(int a,int b ,int& x, int& y)
{
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    int x1, y1;
    int gcd = euclid(b%a, a, x1, y1);
    x = y1 - (b/a) * x1;
    y = x1;
    return gcd;
}

int inver(int a)
{
    int x,y;
    int g=euclid(a,mod,x,y);
    return (x%mod+mod)%mod;
}

//GCD
int gcd(int a,int b)
{
    if(a>b)swap(a,b); if(b==0)return a; return gcd(a%b,b);
}

//PRIME NO
int no;
void primes(int no,bool prime[])
{
    for(int p=2;p*p<=no;p++){   if(prime[p])  {    for(int i=p*p;i<=no;i+=p)prime[i]=false; }   }
}

//DONT ALLOW OVERFLOW
int mul(int a,int b)
{   return ((a*1LL*b)%mod);   }

//TRIE FOR INSERTION DELETION AND SEARCH ALL IN O(L)
class trie
{public:
    bool isLeaf;
    tie* children[26];
    trie()
    {   this->isLeaf=false;
        for(int i=0;i<26;i++){
            this->children[i]=nullptr;
        }   }
    void insert(string key);
    bool search(string key);
    bool havechild(trie* hh);
    bool deletion(trie*&curr,string key);
};
bool trie::havechild(trie* hh)
{
    for(int i=0;i<26;i++)
        if(hh->children[i])return true;
    return false;
}
bool trie::deletion(trie*& curr, string key)
{
    if(curr==nullptr)return false;
    if(key.length()){
        if(curr->isLeaf==false && curr->children[key[0]-'a'] && deletion(curr->children[key[0]-'a'],key.substr(1)) ){
            if(havechild(curr)){
                return false;
            }
            else{
                delete curr;
                curr=nullptr;
                return true;
            }
        }
    }
    if(key.length()==0 && curr->isLeaf){
        if(havechild(curr)){
            curr->isLeaf=false;
            return false;
        }
        else{
            delete curr;
            curr=nullptr;
            return true;
        }
    }
    return false;
}
void trie::insert(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            curr->children[index]=new trie();
        curr=curr->children[index];
    }
    curr->isLeaf=true;;
}
bool trie::search(string key)
{
    trie* curr=this;
    for(int i=0;i<key.length();i++){
        int index=key[i]-'a';
        if(!curr->children[index])
            return false;
        curr=curr->children[index];
    }
    return curr->isLeaf;
}
//trie* head=new trie();
//head->insert("1009");
//head->insert("2009");
//head->insert("hello");
//head->search("1009");
//head->deletion("hello");
//if(head==nullptr)cout<<"trie empty"l
*/

int main()
{
    fast_io;

    // ANS B
    int T; cin>>T;
    while(T--){
        int n; cin>>n;
        vector<vector<int>> v(n+1); vector<int > ans(n+1,-1);
        for(int i=0;i<n;i++){
            int x; cin>>x;
            v[x].pb(i);
        }
        int y=n+1;
        for(int i=0;i<n;i++){
            if(v[i].size()==0)continue;
            int val=max(v[i][0],n-1-v[i][v[i].size()-1])+1;
            for(int j=1;j<v[i].size();j++){
                val=max(val,v[i][j]-v[i][j-1]);
            }
            for(int j=val;j<y;j++){
                ans[j]=i;
            }
            y=min(y,val);
        }
        for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
        cout<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{   int t;cin>>t;
    while(t--){
        int n;cin>>n;
        vector<int> v(n),a(n,-1),c(n+1,INT_MAX);
        for(int i=0;i<n;i++)cin>>v[i];
        int l=n-(n/2)-1;int r=n-(n/2)-(n%2);
        int mini=INT_MAX;
        for(int i=(n/2);i<n;i++){
            if(l>=0&&l<n){
                mini=min(v[l],mini);
            }
            if(r>=0&&r<n){
                mini=min(v[r],mini);
            }
            l--;r++;
            a[i]=mini;
        }
        vector<vector<int>> idk(n+1);
        for(int i=0;i<n;i++){
            idk[v[i]].push_back(i);
        }
        for(int i=0;i<=n;i++){
            //int mindis;
            if((int)idk[i].size()>0){
            int s=idk[i][0];int maxi=0;
            for(int j=1;j<(int)idk[i].size();j++){
                if(idk[i][j]-s>maxi)maxi=idk[i][j]-s;
                s=idk[i][j];
            }
            maxi=max(maxi,n-idk[i].back());
            maxi=max(maxi,idk[i].front()+1);
            c[maxi]=min(c[maxi],i);
            //cout<<maxi<<" "<<i<<endl;
        }
    }
        for(int i=0;i<n/2;i++){
            if(c[i+1]!=INT_MAX){
                a[i]=c[i+1];
                if(i!=0&&a[i-1]!=-1)a[i]=min(a[i],a[i-1]);
            }
            else if(i!=0)a[i]=a[i-1];
            else a[i]=-1;
            //cout<<c[i+1]<<" ";
        }
        //cout<<endl;
        for(int i=0;i<n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{   int t;cin>>t;
    while(t--){
        int n;cin>>n;
        vector<int> v(n),a(n,-1),c(n+1,INT_MAX);
        for(int i=0;i<n;i++)cin>>v[i];
        int l=n-(n/2)-1;int r=n-(n/2)-(n%2);
        int mini=INT_MAX;
        for(int i=(n/2);i<n;i++){
            if(l>=0&&l<n){
                mini=min(v[l],mini);
            }
            if(r>=0&&r<n){
                mini=min(v[r],mini);
            }
            l--;r++;
            a[i]=mini;
        }
        vector<vector<int>> idk(n+1);
        for(int i=0;i<n;i++){
            idk[v[i]].push_back(i);
        }
        for(int i=0;i<=n;i++){
            //int mindis;
            if((int)idk[i].size()>0){
            int s=idk[i][0];int maxi=0;
            for(int j=1;j<(int)idk[i].size();j++){
                if(idk[i][j]-s>maxi)maxi=idk[i][j]-s;
                s=idk[i][j];
            }
            maxi=max(maxi,n-idk[i].back());
            maxi=max(maxi,idk[i].front()+1);
            c[maxi]=min(c[maxi],i);
            //cout<<maxi<<" "<<i<<endl;
        }
        }
        for(int i=0;i<n;i++){
            if(i!=0){
                if(a[i-1]!=-1)a[i]=min(a[i-1],c[i+1]);
                else if(c[i+1]!=INT_MAX)a[i]=c[i+1];
                else a[i]=-1;
            }
            else{
                if(c[1]!=INT_MAX)a[i]=c[1];
                else a[i]=-1;
            }
        }
        //cout<<endl;
        for(int i=0;i<n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{   int t;cin>>t;
    while(t--){
        int n;cin>>n;
        vector<int> v(n),a(n,-1),c(n+1,INT_MAX);
        for(int i=0;i<n;i++)cin>>v[i];
        int l=n-(n/2)-1;int r=n-(n/2)-(n%2);
        int mini=INT_MAX;
        for(int i=(n/2);i<n;i++){
            if(l>=0&&l<n){
                mini=min(v[l],mini);
            }
            if(r>=0&&r<n){
                mini=min(v[r],mini);
            }
            l--;r++;
            a[i]=mini;
        }
        vector<vector<int>> idk(n+1);
        for(int i=0;i<n;i++){
            idk[v[i]].push_back(i);
        }
        for(int i=0;i<=n;i++){
            //int mindis;
            if((int)idk[i].size()>0){
            int s=idk[i][0];int maxi=0;
            for(int j=1;j<(int)idk[i].size();j++){
                if(idk[i][j]-s>maxi)maxi=idk[i][j]-s;
                s=idk[i][j];
            }
            maxi=max(maxi,n-idk[i].back());
            maxi=max(maxi,idk[i].front()+1);
            c[maxi]=min(c[maxi],i);
            //cout<<maxi<<" "<<i<<endl;
        }
    }
        for(int i=0;i<n/2;i++){
            // if(c[i+1]!=INT_MAX){
            //     a[i]=c[i+1];
            //     if(i!=0&&a[i-1]!=-1)a[i]=min(a[i],a[i-1]);
            // }
            // else if(i!=0)a[i]=a[i-1];
            // else a[i]=-1;
            //cout<<c[i+1]<<" ";
            if(i!=0){
                if(a[i-1]!=-1)a[i]=min(a[i-1],c[i+1]);
                else if(c[i+1]!=INT_MAX)a[i]=c[i+1];
                else a[i]=-1;
            }
            else{
                if(c[1]!=INT_MAX)a[i]=c[1];
                else a[i]=-1;
            }
        }
        //cout<<endl;
        for(int i=0;i<n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{   int t;cin>>t;
    while(t--){
        int n;cin>>n;
        vector<int> v(n),a(n,-1),c(n+1,INT_MAX);
        for(int i=0;i<n;i++)cin>>v[i];
        // int l=n-(n/2)-1;int r=n-(n/2)-(n%2);
        // int mini=INT_MAX;
        // for(int i=(n/2);i<n;i++){
        //     if(l>=0&&l<n){
        //         mini=min(v[l],mini);
        //     }
        //     if(r>=0&&r<n){
        //         mini=min(v[r],mini);
        //     }
        //     l--;r++;
        //     a[i]=mini;
        // }
        vector<vector<int>> idk(n+1);
        for(int i=0;i<n;i++){
            idk[v[i]].push_back(i);
        }
        for(int i=0;i<=n;i++){
            //int mindis;
            if((int)idk[i].size()>0){
            int s=idk[i][0];int maxi=0;
            for(int j=1;j<(int)idk[i].size();j++){
                if(idk[i][j]-s>maxi)maxi=idk[i][j]-s;
                s=idk[i][j];
            }
            maxi=max(maxi,n-idk[i].back());
            maxi=max(maxi,idk[i].front()+1);
            c[maxi]=min(c[maxi],i);
            //cout<<maxi<<" "<<i<<endl;
        }
    }
        for(int i=0;i<n;i++){
            if(c[i+1]!=INT_MAX){
                a[i]=c[i+1];
            }
            else a[i]=-1;
            //cout<<c[i+1]<<" ";
        }
        //cout<<endl;
        for(int i=0;i<n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{   int t;cin>>t;
    while(t--){
        int n;cin>>n;
        vector<int> v(n),a(n,-1),c(n+1,INT_MAX);
        for(int i=0;i<n;i++)cin>>v[i];
        int l=n-(n/2)-1;int r=n-(n/2)-(n%2);
        int mini=INT_MAX;
        for(int i=(n/2);i<n;i++){
            if(l>=0&&l<n){
                mini=min(v[l],mini);
            }
            if(r>=0&&r<n){
                mini=min(v[r],mini);
            }
            l--;r++;
            a[i]=mini;
        }
        vector<vector<int>> idk(n+1);
        for(int i=0;i<n;i++){
            idk[v[i]].push_back(i);
        }
        for(int i=0;i<=n;i++){
            //int mindis;
            if((int)idk[i].size()>0){
            int s=idk[i][0];int maxi=0;
            for(int j=1;j<(int)idk[i].size();j++){
                if(idk[i][j]-s>maxi)maxi=idk[i][j]-s;
                s=idk[i][j];
            }
            maxi=max(maxi,n-idk[i].back());
            maxi=max(maxi,idk[i].front()+1);
            c[maxi]=min(c[maxi],i);
            //cout<<maxi<<" "<<i<<endl;
        }
    }
        for(int i=0;i<n/2;i++){
            if(c[i+1]!=INT_MAX){
                a[i]=c[i+1];
            }
            //cout<<c[i+1]<<" ";
        }
        //cout<<endl;
        for(int i=0;i<n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }

    return 0;
}


// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll const mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {
    bool prim[n+1];
    memset(prim, true, sizeof(prim));
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
ll const N = 3e5+5;
vi a(N), last(N,0), f(N,0), ans(N, -1);
void solve(){
    ll n;
    cin >> n;
    last.assign(n+5,0);
    f.assign(n+5,0);
    ans.assign(n+5,-1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++){
        ll x = a[i];
        f[i] = max(f[x], x - last[i] );
        last[i] = 0;
    }
    for(int i = 1; i <= n; i++){
        f[i] = max(f[i], n - f[i] + 1);
        for(int j = f[i]; j <= n and ans[j] == -1; j++)
            ans[j] = i;
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] <<" ";
    cout << "\n";
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio;
    clock_t zzzz = clock();
    ll T;
    T=1;
    cin>>T;
    while(T--){
        solve();
    }
    debug("Total Time: %.3f\n", (double)(clock() - zzzz) / CLOCKS_PER_SEC);
   return 0;
}


// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll const mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {
    bool prim[n+1];
    memset(prim, true, sizeof(prim));
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
ll const N = 3e5+5;
vi a(N), last(N,0), f(N,0), ans(N, -1);
void solve(){
    ll n;
    cin >> n;
    last.assign(n+5,0);
    f.assign(n+5,0);
    ans.assign(n+5,-1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++){
        ll x = a[i];
        f[i] = max(f[x], x - last[i] );
        last[i] = 0;
    }
    for(int i = 1; i <= n; i++){
        f[i] = max(f[i], n - last[i] + 1);
        for(int j = f[i]; j <= n and ans[j] == -1; j++)
            ans[j] = i;
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] <<" ";
    cout << "\n";
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio;
    clock_t zzzz = clock();
    ll T;
    T=1;
    cin>>T;
    while(T--){
        solve();
    }
    debug("Total Time: %.3f\n", (double)(clock() - zzzz) / CLOCKS_PER_SEC);
   return 0;
}


// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll const mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {
    bool prim[n+1];
    memset(prim, true, sizeof(prim));
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
ll const N = 3e5+5;
vi a(N), last(N,0), f(N,0), ans(N, -1);
void solve(){
    ll n;
    cin >> n;
    last.assign(n+5,0);
    f.assign(n+5,0);
    ans.assign(n+5,-1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++){
        ll x = a[i];
        f[i] = max(f[i], x - last[i] + 1);
        last[i] = 0;
    }
    for(int i = 1; i <= n; i++){
        f[i] = max(f[i], n - f[i] + 1);
        for(int j = f[i]; j <= n and ans[j] == -1; j++)
            ans[j] = i;
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] <<" ";
    cout << "\n";
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio;
    clock_t zzzz = clock();
    ll T;
    T=1;
    cin>>T;
    while(T--){
        solve();
    }
    debug("Total Time: %.3f\n", (double)(clock() - zzzz) / CLOCKS_PER_SEC);
   return 0;
}


// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll const mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {
    bool prim[n+1];
    memset(prim, true, sizeof(prim));
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
ll const N = 3e5+5;
vi a(N), last(N,0), f(N,0), ans(N, -1);
void solve(){
    ll n;
    cin >> n;
    last.assign(n+5,0);
    f.assign(n+5,0);
    ans.assign(n+5,-1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++){
        ll x = a[i];
        f[x] = max(f[x], i - last[x] );
        last[x] = i;
    }
    for(int i = 1; i <= n; i++){
        f[i] = max(f[i], n - last[i] + 1);
        for(int j = f[i]; j <= n and ans[j] == -1; j++)
            ans[j] = i;
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] <<" ";
    cout << "\n";
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio;
    clock_t zzzz = clock();
    ll T;
    T=1;
    cin>>T;
    while(T--){
        solve();
    }
    debug("Total Time: %.3f\n", (double)(clock() - zzzz) / CLOCKS_PER_SEC);
   return 0;
}


// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll const mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {
    bool prim[n+1];
    memset(prim, true, sizeof(prim));
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) {
            for (int i=p*p; i<=n; i += p)
                prim[i] = false;
        }
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v;
}
ll const N = 3e5+5;
vi a(N), last(N,0), f(N,0), ans(N, -1);
void solve(){
    ll n;
    cin >> n;
    last.assign(n+5,0);
    f.assign(n+5,0);
    ans.assign(n+5,-1);
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i <= n; i++){
        ll x = a[i];
        f[i] = max(f[i], x - last[i]);
        last[i] = 0;
    }
    for(int i = 1; i <= n; i++){
        f[i] = max(f[i], n - f[i] + 1);
        for(int j = f[i]; j <= n and ans[j] == -1; j++)
            ans[j] = i;
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] <<" ";
    cout << "\n";
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio;
    clock_t zzzz = clock();
    ll T;
    T=1;
    cin>>T;
    while(T--){
        solve();
    }
    debug("Total Time: %.3f\n", (double)(clock() - zzzz) / CLOCKS_PER_SEC);
   return 0;
}


#include <bits/stdc++.h>
#define _itr ::iterator
#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define ford(i, x, y) for (ll i = x; i > y; --i)
#define forne(i, x, y) for (ll i = x; i <= y; ++i)
#define forde(i, x, y) for (ll i = x; i >= y; --i)
#define rd(x) cin >> x; cin.ignore();
#define rdstr(x) getline(cin, x);
#define rdarr(x, y) for (ll i = 0; i < y; ++i) cin >> x[i];
#define rdmtr(x, y, z) for (ll i = 0; i < y; ++i) for (ll j = 0; j < z; ++j) cin >> x[i][j];
#define pb push_back

#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;

const ll MaxN = 3e5 + 7;
const ll MaxM = 1e2 + 7;
const ll MDL = 1e9 + 7;
const ll INF = 1e18 + 7;

typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef ll arr[MaxN];

ll REPIT = 1;

const bool MQ = true;

ll n, m;
arr so;
map<ll, vector<ll> > mp;
priority_queue<pi> res;
arr pos;

//bool Find(ll st, ll en, ll x)
//{
//    forn(i, st, en)
//     if (so[i] == x) return 1;
//    return 0;
//}

void Solve()
{
    cin >> n; rdarr(so, n); mp.clear();
//    forn(a, 0, n)
//    {
//        bool ok = 1;
//        forde(i, n, 1)
//        {
//            forne(j, 0, n - i)
//            {
//                if (!Find(j, j + i, so[a]))
//                {
//                    cout << so[a] << ' ' << i + 1 << '\n';
//                    ok = 0;
//                    break;
//                }
//            }
//            if (!ok) break;
//        }
//        if (ok) cout << so[a] << ' ' << 1 << '\n';
//    }
//    cout << '\n';
    forn(i, 0, n) mp[so[i]].push_back(i);
    for (auto v : mp)
    {
        ll u = v.X; vi p = v.Y;
        ll r = max(p.front() + 1, n - p.back());
        for (ll i = 1; i < (ll)p.size(); ++i) r = max(p[i] - p[i - 1], r);
        res.push({-u, -(r - 1)});
//        cout << u << ' ' << r << '\n';
    }
    ll mx = n - 1;
    fill(pos, pos + n, -1);
    while (!res.empty())
    {
        pi u = res.top(); res.pop();
        ll st = -u.Y;
        forne(i, st, mx) pos[i] = -u.X;
        mx = st - 1;
    }
    forn(i, 0, n) cout << pos[i] << ' '; cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef OFFLINE
    freopen("input.inp", "r", stdin);
    #endif
    if (MQ == true)
    {
        rd(REPIT);
    }
    while (REPIT--) Solve();
    cout.flush();
    #ifdef OFFLINE
    fclose(stdin);
    #endif
}


#include <bits/stdc++.h>
#define _itr ::iterator
#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define ford(i, x, y) for (ll i = x; i > y; --i)
#define forne(i, x, y) for (ll i = x; i <= y; ++i)
#define forde(i, x, y) for (ll i = x; i >= y; --i)
#define rd(x) cin >> x; cin.ignore();
#define rdstr(x) getline(cin, x);
#define rdarr(x, y) for (ll i = 0; i < y; ++i) cin >> x[i];
#define rdmtr(x, y, z) for (ll i = 0; i < y; ++i) for (ll j = 0; j < z; ++j) cin >> x[i][j];
#define pb push_back

#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;

const ll MaxN = 1e5 + 7;
const ll MaxM = 1e2 + 7;
const ll MDL = 1e9 + 7;
const ll INF = 1e18 + 7;

typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef ll arr[MaxN];

ll REPIT = 1;

const bool MQ = true;

ll n, m;
arr so;
map<ll, vector<ll> > mp;
priority_queue<pi> res;
arr pos;

void Solve()
{
    cin >> n; rdarr(so, n); mp.clear();
    forn(i, 0, n) mp[so[i]].push_back(i);
    for (auto v : mp)
    {
        ll u = v.X; vi p = v.Y;
        ll r = max(p.front() + 1, n - p.back());
        for (ll i = 1; i < (ll)p.size(); ++i) r = max(p[i] - p[i - 1], r);
        res.push({-u, -(r - 1)});
        cout << u << ' ' << r << '\n';
    }
    ll mx = n - 1;
    fill(pos, pos + n, -1);
    while (!res.empty())
    {
        pi u = res.top(); res.pop();
        ll st = -u.Y; if (st > mx) continue;
        forne(i, st, mx) pos[i] = -u.X;
        mx = st - 1;
    }
    forn(i, 0, n) cout << pos[i] << ' '; cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef OFFLINE
    freopen("input.inp", "r", stdin);
    #endif
    if (MQ == true)
    {
        rd(REPIT);
    }
    while (REPIT--) Solve();
    cout.flush();
    #ifdef OFFLINE
    fclose(stdin);
    #endif
}