As you know, the girl Dora is always looking for something. This time she was given a permutation, and she wants to find such a subsegment of it that none of the elements at its ends is either the minimum or the maximum of the entire subsegment. More formally, you are asked to find the numbers $l$ and $r$ $(1 \leq l \leq r \leq n)$ such that $a_l \neq \min(a_l, a_{l + 1}, \ldots, a_r)$, $a_l \neq \max(a_l, a_{l + 1}, \ldots, a_r)$ and $a_r \neq \min(a_l, a_{l + 1}, \ldots, a_r)$, $a_r \neq \max(a_l, a_{l + 1}, \ldots, a_r)$.

A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in any order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ occurs twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$, but $4$ is present in the array).

Help Dora find such a subsegment, or tell her that such a subsegment does not exist.


-----Input-----

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Description of the test cases follows.

For each test case, the first line contains one integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of permutation.

The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of permutation.

It is guarented that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, output $-1$ if the desired subsegment does not exist.

Otherwise, output two indexes $l, r$ such that $[a_{l}, a_{l + 1}, \ldots, a_{r}]$ satisfies all conditions.

If there are several solutions, then output any of them.


-----Examples-----

Input
4
3
1 2 3
4
2 1 4 3
7
1 3 2 4 6 5 7
6
2 3 6 5 4 1
Output
-1
1 4
2 6
-1


-----Note-----

In the first and fourth test cases, it can be shown that there are no desired subsegments.

In the second test case, the subsegment $[1, 4]$ satisfies all the conditions, because $\max(a_1, a_2, a_3, a_4) = 4, \min(a_1, a_2, a_3, a_4) = 1$, as we see, all the conditions are met.

In the third test case, the subsegment $[2, 6]$ also satisfies all the conditions described.

Difficulty: EASY
Tags: Data structures

Amortized analysis

Constructive algorithms
Skill types: Amortized analysis

Data structures

Starter code:

Solutions:
import sys

def solve():
	inp = sys.stdin.readline
	n = int(inp())
	a = list(map(int, inp().split()))
	m = 1
	M = n
	i = 0
	j = n - 1
	while i <= j:
		if a[i] == m:
			i += 1
			m += 1
		elif a[i] == M:
			i += 1
			M -= 1
		elif a[j] == m:
			j -= 1
			m += 1
		elif a[j] == M:
			j -= 1
			M -= 1
		else:
			break
	if i < j:
		print(i + 1, j + 1)
	else:
		print(-1)

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


import sys
input = sys.stdin.readline

def solver():
	n = int(input())
	arr = list(map(int, input().split()))
	(mn, mx) = (1, n)
	(i, j) = (0, n - 1)
	(prev_i, prev_j) = (None, None)
	while i < j:
		(prev_i, prev_j) = (i, j)
		if arr[i] == mn:
			i += 1
			mn += 1
		elif arr[i] == mx:
			i += 1
			mx -= 1
		if arr[j] == mn:
			j -= 1
			mn += 1
		elif arr[j] == mx:
			j -= 1
			mx -= 1
		if prev_i == i and prev_j == j:
			print(i + 1, j + 1)
			return
	print(-1)
T = int(input())
for _ in range(T):
	solver()


def solution(n, a: list):
	(a_min, a_max) = (1, n)
	(left, right) = (0, n - 1)
	flag = True
	while flag:
		flag = False
		while left < right:
			if a[left] == a_min:
				a_min += 1
				left += 1
				flag = True
				continue
			if a[left] == a_max:
				a_max -= 1
				left += 1
				flag = True
				continue
			break
		while left < right:
			if a[right] == a_min:
				a_min += 1
				right -= 1
				flag = True
				continue
			if a[right] == a_max:
				a_max -= 1
				right -= 1
				flag = True
				continue
			break
	if left >= right:
		print(-1)
	else:
		print(left + 1, right + 1)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	solution(n, a)


def solver():
	n = int(input())
	arr = list(map(int, input().split()))
	mn = 1
	mx = n
	i = 0
	j = n - 1
	prev_i = 0
	prev_j = 0
	while i < j:
		prev_i = i
		prev_j = j
		if arr[i] == mn:
			i += 1
			mn += 1
		elif arr[i] == mx:
			i += 1
			mx -= 1
		if arr[j] == mn:
			j -= 1
			mn += 1
		elif arr[j] == mx:
			j -= 1
			mx -= 1
		if prev_i == i and prev_j == j:
			print(i + 1, j + 1)
			return
	print(-1)
	return
t = int(input())
for _ in range(t):
	solver()


def solve(a):
	n = len(a)
	c_min = 1
	c_max = n
	l = 0
	r = n - 1
	while l <= r:
		if c_min == a[l]:
			c_min += 1
			l += 1
		elif c_max == a[l]:
			c_max -= 1
			l += 1
		elif c_min == a[r]:
			c_min += 1
			r -= 1
		elif c_max == a[r]:
			c_max -= 1
			r -= 1
		else:
			return [l, r]
	return []
t = int(input())
ans = []
for ti in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans.append(solve(a))
for a in ans:
	if a:
		print(' '.join([str(x + 1) for x in a]))
	else:
		print(-1)


def helper(arr):
	(maxi, mini) = (len(arr), 1)
	(l, r) = (0, len(arr) - 1)
	while l < r:
		y = False
		if arr[l] == maxi or arr[l] == mini:
			y = True
			if arr[l] == maxi:
				maxi -= 1
			elif arr[l] == mini:
				mini += 1
			l += 1
		elif arr[r] == maxi or arr[r] == mini:
			y = True
			if arr[r] == maxi:
				maxi -= 1
				r -= 1
			elif arr[r] == mini:
				mini += 1
				r -= 1
		if not y:
			return str(l + 1) + ' ' + str(r + 1)
	return '-1'
for i in range(int(input())):
	n = int(input())
	print(helper(list(map(int, input().split()))))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(mn, mx) = (1, n)
	while l <= r:
		if a[l] == mn:
			l += 1
			mn += 1
		elif a[l] == mx:
			l += 1
			mx -= 1
		elif a[r] == mn:
			r -= 1
			mn += 1
		elif a[r] == mx:
			r -= 1
			mx -= 1
		else:
			break
	if l <= r:
		print(l + 1, r + 1)
	else:
		print(-1)
t = int(input())
for _ in range(t):
	solve()


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	left = 0
	right = n - 1
	mn = 1
	mx = n
	while left <= right:
		if arr[left] == mn:
			left += 1
			mn += 1
		elif arr[left] == mx:
			left += 1
			mx -= 1
		elif arr[right] == mn:
			right -= 1
			mn += 1
		elif arr[right] == mx:
			right -= 1
			mx -= 1
		else:
			break
	if left <= right:
		print(left + 1, right + 1)
		return
	else:
		print(-1)
		return
t = int(input())
while t:
	solve()
	t -= 1


from collections import deque

def getint():
	return int(input())

def getfloat():
	return float(input())

def getints():
	return list(map(int, input().split()))

def getfloats():
	return list(map(float, input().split()))

def answer():
	n = getint()
	p = getints()
	l = 0
	r = n - 1
	nowmin = 1
	nowmax = n
	while l < r:
		if nowmin == p[l]:
			l += 1
			nowmin += 1
		elif nowmin == p[r]:
			r -= 1
			nowmin += 1
		elif nowmax == p[l]:
			l += 1
			nowmax -= 1
		elif nowmax == p[r]:
			r -= 1
			nowmax -= 1
		else:
			break
	if l == r:
		print(-1)
	else:
		print(l + 1, r + 1)
T = getint()
for i in range(T):
	answer()


def ankit():
	n = int(input())
	essd_ar = list(map(int, input().strip().split()))
	uvi = 0
	uvvj = 0
	minimun = 1
	maximum = n
	xx = 0
	yy = n - 1
	while xx < yy:
		uvi = xx
		uvvj = yy
		if essd_ar[xx] == minimun:
			xx += 1
			minimun += 1
		elif essd_ar[xx] == maximum:
			xx += 1
			maximum -= 1
		if essd_ar[yy] == minimun:
			yy -= 1
			minimun += 1
		elif essd_ar[yy] == maximum:
			yy -= 1
			maximum -= 1
		if uvi == xx and uvvj == yy:
			print(xx + 1, yy + 1)
			return
	print(-1)
	return
for _ in range(int(input())):
	ankit()


def main():
	t = int(input())
	for _ in range(t):
		res = alg()
		print(res)

def alg():
	n = int(input())
	a = [int(x) for x in input().split()]
	l = 0
	r = n - 1
	curMin = 1
	curMax = n
	while r - l > 2:
		if a[l] == curMin:
			curMin += 1
			l += 1
		elif a[r] == curMin:
			curMin += 1
			r -= 1
		elif a[l] == curMax:
			curMax -= 1
			l += 1
		elif a[r] == curMax:
			curMax -= 1
			r -= 1
		else:
			break
	if r < 0 or l >= n or r - l < 3:
		res = -1
	else:
		res = str(l + 1) + ' ' + str(r + 1)
	return res
main()


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	i = 0
	j = n - 1
	mini = 1
	maxm = n
	flg = 0
	while i < j:
		if lst[i] == mini:
			mini = mini + 1
			i = i + 1
		elif lst[i] == maxm:
			maxm = maxm - 1
			i = i + 1
		elif lst[j] == mini:
			mini = mini + 1
			j = j - 1
		elif lst[j] == maxm:
			maxm = maxm - 1
			j = j - 1
		else:
			flg = 1
			break
	if flg == 0:
		print(-1)
	else:
		print(i + 1, ' ', j + 1)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(minx, maxn) = (1, n)
	while l <= r:
		if a[l] == minx:
			l += 1
			minx += 1
		elif a[l] == maxn:
			l += 1
			maxn -= 1
		elif a[r] == minx:
			r -= 1
			minx += 1
		elif a[r] == maxn:
			r -= 1
			maxn -= 1
		else:
			break
	if l > r:
		print(-1)
	else:
		print(l + 1, r + 1)
t = int(input())
while t:
	t -= 1
	solve()


t = int(input())
for j in range(0, t):
	c = int(input())
	a = list(map(int, input().split()))
	s = 1
	t = c
	indexi = 0
	indexii = c - 1
	f = 0
	for i in range(0, c - 3):
		if a[indexi] == s:
			indexi = indexi + 1
			s = s + 1
		elif a[indexii] == s:
			s = s + 1
			indexii = indexii - 1
		elif a[indexi] == t:
			indexi = indexi + 1
			t = t - 1
		elif a[indexii] == t:
			indexii = indexii - 1
			t = t - 1
		else:
			f = 1
			print(indexi + 1, indexii + 1)
			break
	if f == 0:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	min = 1
	max = n
	l = 0
	r = n - 1
	while l != r:
		if arr[l] == max:
			l += 1
			max -= 1
		elif arr[l] == min:
			l += 1
			min += 1
		elif arr[r] == max:
			r -= 1
			max -= 1
		elif arr[r] == min:
			r -= 1
			min += 1
		else:
			break
	if l == r:
		print(-1)
	else:
		print(l + 1, r + 1)


def solve(n, nums):
	(l, r) = (1, n)
	(i, j) = (0, n - 1)
	while i <= j and j < n:
		if nums[i] not in (l, r) and nums[j] not in (l, r):
			break
		if nums[i] == l:
			l += 1
			i += 1
		elif nums[i] == r:
			r -= 1
			i += 1
		if nums[j] == l:
			l += 1
			j -= 1
		elif nums[j] == r:
			r -= 1
			j -= 1
	if i <= j:
		return f'{i + 1} {j + 1}'
	return -1
T = int(input())
for t in range(T):
	n = int(input())
	nums = list(map(int, input().split()))
	print(solve(n, nums))


def validate(c, l, r):
	mn = 1
	mx = r + 1
	while l != r:
		if c[l] == mn:
			l += 1
			mn += 1
			continue
		if c[l] == mx:
			l += 1
			mx -= 1
			continue
		if c[r] == mn:
			r -= 1
			mn += 1
			continue
		if c[r] == mx:
			r -= 1
			mx -= 1
			continue
		print(str(l + 1) + ' ' + str(r + 1))
		return
	print('-1')
	return
t = int(input())
for _ in range(t):
	u = int(input())
	c = [int(x) for x in input().split()]
	validate(c, 0, len(c) - 1)


for _ in range(int(input())):
	(mn, mx) = (1, int(input()))
	a = [int(i) for i in input().split()]
	(l, r) = (0, mx - 1)
	pas = False
	while r - l >= 3:
		if a[l] == mn:
			mn += 1
			l += 1
		elif a[l] == mx:
			mx -= 1
			l += 1
		elif a[r] == mn:
			mn += 1
			r -= 1
		elif a[r] == mx:
			mx -= 1
			r -= 1
		else:
			pas = True
			break
	if pas:
		print(l + 1, r + 1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	(mn, mx) = (1, n)
	(l, r) = (0, n - 1)
	while l < r:
		if a[l] == mn:
			l += 1
			mn += 1
		elif a[l] == mx:
			l += 1
			mx -= 1
		elif a[r] == mn:
			r -= 1
			mn += 1
		elif a[r] == mx:
			r -= 1
			mx -= 1
		else:
			break
	print(l + 1, r + 1) if l < r else print(-1)


from typing import List

def solve() -> None:
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(mn, mx) = (1, n)
	while l <= r:
		if a[l] == mn:
			l += 1
			mn += 1
		elif a[l] == mx:
			l += 1
			mx -= 1
		elif a[r] == mn:
			r -= 1
			mn += 1
		elif a[r] == mx:
			r -= 1
			mx -= 1
		else:
			break
	if l <= r:
		print(l + 1, r + 1)
	else:
		print(-1)
q = int(input())
for _ in range(q):
	solve()


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	mine = 1
	maxe = n
	(l, r) = (0, n - 1)
	while l < r:
		if nums[l] == mine:
			l += 1
			mine += 1
		elif nums[l] == maxe:
			l += 1
			maxe -= 1
		elif nums[r] == maxe:
			r -= 1
			maxe -= 1
		elif nums[r] == mine:
			r -= 1
			mine += 1
		else:
			break
	if l >= r:
		print(-1)
	else:
		print(l + 1, r + 1)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	k = 1
	l = n
	while i <= j:
		if a[i] == k:
			k += 1
			i += 1
		elif a[j] == k:
			j -= 1
			k += 1
		elif a[i] == l:
			l -= 1
			i += 1
		elif a[j] == l:
			l -= 1
			j -= 1
		else:
			print(i + 1, j + 1)
			break
	else:
		print(-1)
	t -= 1


test_case = int(input())
for test in range(test_case):
	n = int(input())
	A = list(map(int, input().split()))
	Max = n
	Min = 1
	i = 0
	j = n - 1
	T = True
	while i < j:
		a = i
		b = j
		if A[i] == Min:
			i += 1
			Min += 1
		elif A[i] == Max:
			i += 1
			Max -= 1
		if A[j] == Min:
			j -= 1
			Min += 1
		elif A[j] == Max:
			j -= 1
			Max -= 1
		if a == i and b == j:
			print(i + 1, j + 1)
			T = False
			break
	if T:
		print(-1)


def f(le, lst):
	min = 1
	max = le
	star = 0
	end = le - 1
	while star < end:
		if lst[star] == min:
			min = min + 1
			star = star + 1
		elif lst[star] == max:
			max = max - 1
			star = star + 1
		elif lst[end] == min:
			min = min + 1
			end = end - 1
		elif lst[end] == max:
			max = max - 1
			end = end - 1
		else:
			break
	if end == star:
		print(-1)
	else:
		print(star + 1, end + 1)
for t in range(int(input())):
	le = int(input())
	lst = list(map(int, input().split(' ')))
	f(le, lst)


import heapq
from collections import *
import math

def lcm(a, b):
	return a * b // math.gcd(a, b)

def factorial(n):
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i
		fact %= 1000000007
	return fact

def primeFactors(n):
	ans = []
	d = defaultdict(int)
	while n % 2 == 0:
		d[2] += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			d[i] += 1
			n = n / i
	if n > 2:
		d[n] += 1
	return d

def Divisors(n):
	i = 1
	ans = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(n // i)
		i = i + 1
	return ans

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	i = 0
	j = n - 1
	mini = 1
	maxi = n
	while True:
		if i == j:
			print(-1)
			break
		if a[i] == mini or a[i] == maxi:
			if a[i] == mini:
				mini += 1
			else:
				maxi -= 1
			i += 1
		elif a[j] == mini or a[j] == maxi:
			if a[j] == mini:
				mini += 1
			else:
				maxi -= 1
			j -= 1
		else:
			print(i + 1, j + 1)
			break
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = n - 1
	L = 1
	R = n
	while l <= r:
		if a[l] == L:
			l += 1
			L += 1
			continue
		if a[r] == R:
			r -= 1
			R -= 1
			continue
		if a[l] == R:
			l += 1
			R -= 1
			continue
		if a[r] == L:
			r -= 1
			L += 1
			continue
		print(l + 1, r + 1)
		break
	if l > r:
		print(-1)


import sys
R = lambda : map(int, next(sys.stdin).split())
(t,) = R()
while t:
	t -= 1
	(n,) = R()
	(*a,) = R()
	(mn, mx) = (1, n)
	(l, r) = (0, n - 1)
	while l < r:
		if a[l] == mn:
			l += 1
			mn += 1
		elif a[l] == mx:
			l += 1
			mx -= 1
		elif a[r] == mn:
			r -= 1
			mn += 1
		elif a[r] == mx:
			r -= 1
			mx -= 1
		else:
			break
	print(l + 1, r + 1) if l < r else print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = 0
	r = n - 1
	mn = 1
	mx = n
	while l <= r:
		if arr[l] == mx:
			mx -= 1
			l += 1
		elif arr[l] == mn:
			mn += 1
			l += 1
		elif arr[r] == mx:
			mx -= 1
			r -= 1
		elif arr[r] == mn:
			mn += 1
			r -= 1
		else:
			break
	print(f'{l + 1} {r + 1}' if l <= r else '-1')


x = int(input())
for i in range(x):
	n = int(input())
	test = list(map(int, input().split()))
	low = 1
	high = n
	l = 0
	r = n - 1
	while l < r:
		if test[l] == low:
			l += 1
			low += 1
		elif test[r] == high:
			r -= 1
			high -= 1
		elif test[l] == high:
			high -= 1
			l += 1
		elif test[r] == low:
			low += 1
			r -= 1
		else:
			break
	if l == r and test[l] == low:
		print(-1)
	else:
		print(f'{l + 1} {r + 1}')


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(mi, ma) = (1, n)
	while l <= r:
		if lst[l] == mi:
			l += 1
			mi += 1
		elif lst[l] == ma:
			l += 1
			ma -= 1
		elif lst[r] == mi:
			r -= 1
			mi += 1
		elif lst[r] == ma:
			r -= 1
			ma -= 1
		else:
			break
	print(*((l + 1, r + 1) if l <= r else (-1,)))


import functools
import itertools
import sys
from collections import defaultdict

def solution():
	n = int(input())
	data = list(map(int, input().split()))
	d = dict()
	for (idx, el) in enumerate(data):
		d[el] = idx + 1
	minimum = 1
	maximum = n
	left = 1
	right = n
	while left != right:
		flag_left = False
		flag_right = False
		if d[minimum] == left:
			minimum += 1
			left += 1
		elif d[minimum] == right:
			minimum += 1
			right -= 1
		else:
			flag_left = True
		if left == right:
			break
		if d[maximum] == left:
			maximum -= 1
			left += 1
		elif d[maximum] == right:
			maximum -= 1
			right -= 1
		else:
			flag_right = True
		if flag_left and flag_right:
			break
	if left == right:
		print(-1)
	else:
		print(left, right)
t = int(input())
for _ in range(t):
	solution()


for _ in range(int(input())):
	n = int(input())
	p = [0]
	pt = [int(i) for i in input().split()]
	p = p + pt
	(mx, mn) = (n, 1)
	(i, j) = (1, n)
	while i < j:
		if p[i] == mx:
			mx -= 1
			i += 1
		elif p[i] == mn:
			mn += 1
			i += 1
		elif p[j] == mx:
			mx -= 1
			j -= 1
		elif p[j] == mn:
			mn += 1
			j -= 1
		else:
			break
	if j - i <= 1:
		print(-1)
	else:
		print(*[i, j])


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(-1)
		continue
	(maxx, minn) = (n, 1)
	(p, q) = (0, n - 1)
	flag = 1
	while p < q and flag:
		flag = 0
		if a[p] == maxx or a[p] == minn:
			if a[p] == maxx:
				maxx -= 1
			elif a[p] == minn:
				minn += 1
			p += 1
			flag = 1
		if a[q] == maxx or a[q] == minn:
			if a[q] == maxx:
				maxx -= 1
			elif a[q] == minn:
				minn += 1
			q -= 1
			flag = 1
	if p >= q:
		print(-1)
	else:
		print(p + 1, q + 1)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	(left, right) = (1, n)
	(i, j) = (0, n - 1)
	flag = 0
	while i <= j:
		if l[i] == left or l[i] == right or l[j] == left or (l[j] == right):
			if l[i] == left:
				i += 1
				left += 1
			elif l[i] == right:
				i += 1
				right -= 1
			if l[j] == left:
				j -= 1
				left += 1
			elif l[j] == right:
				j -= 1
				right -= 1
		else:
			flag = 1
			print(i + 1, j + 1)
			break
	if flag == 0:
		print(-1)
	t -= 1


from math import *
for z in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = 1
	q = n
	i = 0
	j = n - 1
	f = 0
	while i < n and j > -1:
		if a[i] == p:
			i += 1
			p += 1
		elif a[i] == q:
			q -= 1
			i += 1
		elif a[j] == p:
			j -= 1
			p += 1
		elif a[j] == q:
			j -= 1
			q -= 1
		else:
			f = 1
			break
	if f == 0:
		print(-1)
	else:
		print(i + 1, j + 1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	min = 1
	max = n
	i = 0
	j = n - 1
	xi = None
	xj = None
	while i < j:
		xi = i
		xj = j
		if arr[i] == min:
			i += 1
			min += 1
		elif arr[i] == max:
			i += 1
			max -= 1
		if arr[j] == min:
			j -= 1
			min += 1
		elif arr[j] == max:
			j -= 1
			max -= 1
		if xi == i and xj == j:
			print(i + 1, j + 1)
			break
	else:
		print(-1)


def print_search_dora(arr, n):
	first = 1
	last = n
	j = n - 1
	i = 0
	while i < j:
		if arr[i] == first:
			first += 1
			i += 1
		elif arr[j] == first:
			first += 1
			j = j - 1
		elif arr[j] == last:
			last -= 1
			j = j - 1
		elif arr[i] == last:
			last -= 1
			i = i + 1
		else:
			print(i + 1, j + 1)
			return
	print(-1)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		print_search_dora(arr, n)
main()


T = int(input())
for t in range(T):
	N = int(input())
	arr = [int(k) for k in input().split()]
	min_sofar = 1
	max_sofar = N
	l = 0
	r = N - 1
	while l < r:
		if arr[l] == min_sofar:
			min_sofar += 1
			l += 1
		elif arr[l] == max_sofar:
			max_sofar -= 1
			l += 1
		elif arr[r] == min_sofar:
			min_sofar += 1
			r -= 1
		elif arr[r] == max_sofar:
			max_sofar -= 1
			r -= 1
		else:
			break
	if l == r:
		print(-1)
	else:
		print(l + 1, r + 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mn = 1
	mx = n
	s = 0
	e = n - 1
	while s < e:
		if a[s] == mn:
			s += 1
			mn += 1
		elif a[s] == mx:
			s += 1
			mx -= 1
		elif a[e] == mn:
			e -= 1
			mn += 1
		elif a[e] == mx:
			e -= 1
			mx -= 1
		else:
			break
	if s < e:
		print(s + 1, e + 1)
	else:
		print(-1)


t = int(input())
for z in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 1
	l = n
	i = 0
	j = n - 1
	while i < j:
		if a[i] == s:
			s += 1
			i += 1
			if a[j] == l:
				j -= 1
				l -= 1
		elif a[i] == l:
			i += 1
			l -= 1
			if a[j] == s:
				j -= 1
				s += 1
		elif a[j] == s:
			j -= 1
			s += 1
		elif a[j] == l:
			j -= 1
			l -= 1
		else:
			break
	if i >= j:
		print(-1)
	else:
		print(i + 1, j + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	minim = 1
	maxim = n
	st = 0
	dr = n - 1
	while st < dr and (a[st] == minim or a[dr] == minim or a[st] == maxim or (a[dr] == maxim)):
		if a[st] == minim:
			minim += 1
			st += 1
		elif a[dr] == minim:
			minim += 1
			dr -= 1
		elif a[st] == maxim:
			maxim -= 1
			st += 1
		elif a[dr] == maxim:
			maxim -= 1
			dr -= 1
	if st == dr:
		print(-1)
	else:
		print(st + 1, dr + 1)


from collections import deque
for testcase in range(int(input())):
	n = int(input())
	list = map(int, input().split())
	queue = deque(list)
	min_val = 1
	max_val = len(queue)
	left = 1
	right = len(queue)
	while len(queue) > 0:
		if queue[-1] == min_val:
			queue.pop()
			right = right - 1
			min_val = min_val + 1
		elif queue[0] == max_val:
			queue.popleft()
			left = left + 1
			max_val = max_val - 1
		elif queue[-1] == max_val:
			queue.pop()
			right = right - 1
			max_val = max_val - 1
		elif queue[0] == min_val:
			queue.popleft()
			left = left + 1
			min_val = min_val + 1
		else:
			break
	if len(queue) == 0:
		print(-1)
	else:
		print(left, right)


import collections
import math
import heapq
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(left, right) = (0, n - 1)
	(cmin, cmax) = (1, n)
	while left < right:
		if arr[left] == cmin:
			cmin += 1
			left += 1
		elif arr[left] == cmax:
			cmax -= 1
			left += 1
		elif arr[right] == cmin:
			cmin += 1
			right -= 1
		elif arr[right] == cmax:
			cmax -= 1
			right -= 1
		else:
			break
	if left < right:
		print(left + 1, right + 1)
	else:
		print(-1)


cases = int(input())
for i in range(0, cases):
	le = int(input())
	a = list(map(int, input().split()))
	mini = 1
	maxi = le
	l = 0
	r = len(a) - 1
	mflag = 0
	while l < r:
		flag = True
		if a[l] == mini:
			flag = False
			l += 1
			mini += 1
		elif a[l] == maxi:
			flag = False
			l += 1
			maxi -= 1
		if a[r] == mini:
			flag = False
			r -= 1
			mini += 1
		elif a[r] == maxi:
			flag = False
			r -= 1
			maxi -= 1
		if flag == True:
			print(l + 1, r + 1)
			mflag = 1
			break
	if mflag == 0:
		print(-1)


n = int(input())
for x in range(n):
	l = int(input())
	start = 0
	end = l - 1
	a = list(map(int, input().split()))
	(mn, mx) = (1, l)
	flag = True
	while flag and end != start and (start < end):
		flag = True
		if a[start] == mn:
			mn += 1
			start += 1
		elif a[start] == mx:
			mx -= 1
			start += 1
		elif a[end] == mn:
			mn += 1
			end -= 1
		elif a[end] == mx:
			mx -= 1
			end -= 1
		else:
			flag = False
	if end == start:
		print(-1)
	else:
		print(start + 1, end + 1)


for _ in range(int(input())):
	n = int(input())
	(a, b) = (1, n)
	(l, r) = (1, n)
	tp = list(map(int, input().split()))
	p = [0] + tp
	f = 1
	while l < r and f:
		t = 0
		if p[l] == a:
			l += 1
			a += 1
			t = 1
		elif p[l] == b:
			l += 1
			b -= 1
			t = 1
		if p[r] == a:
			r -= 1
			a += 1
			t = 1
		elif p[r] == b:
			r -= 1
			b -= 1
			t = 1
		if t == 0:
			f = 0
	if l == r:
		f = 1
	if f == 0:
		print(l, r)
	else:
		print(-1)


t = int(input())
for t1 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	min = 1
	max = n
	i = 0
	j = n - 1
	ind = 0
	while i < j:
		if a[i] == min:
			i += 1
			min += 1
		elif a[i] == max:
			max -= 1
			i += 1
		elif a[j] == min:
			j -= 1
			min += 1
		elif a[j] == max:
			j -= 1
			max -= 1
		else:
			ind = 1
			print(i + 1, j + 1)
			break
	if ind == 0:
		print(-1)


n = int(input())
for _ in range(n):
	k = int(input())
	a = [int(x) for x in input().split(' ')]
	left = 0
	right = k - 1
	nl = 1
	nr = k
	for i in range(k):
		if right - left < 3:
			break
		if a[left] == nl:
			nl += 1
			left += 1
		if a[left] == nr:
			left += 1
			nr -= 1
		if a[right] == nl:
			nl += 1
			right -= 1
		if a[right] == nr:
			nr -= 1
			right -= 1
	if right - left >= 3:
		print(left + 1, right + 1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = 0
	r = n - 1
	curMin = 1
	curMax = n
	Flag = False
	while l != r and (not Flag):
		if arr[l] == curMin:
			l += 1
			curMin += 1
		elif arr[l] == curMax:
			l += 1
			curMax -= 1
		elif arr[r] == curMin:
			r -= 1
			curMin += 1
		elif arr[r] == curMax:
			r -= 1
			curMax -= 1
		else:
			Flag = True
	if l == r:
		print(-1)
	else:
		print(l + 1, r + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	xs = [int(a) for a in input().split()]
	a = 1
	b = n
	i = 0
	j = n - 1
	while j > i:
		if not (xs[i] == a or xs[i] == b or xs[j] == a or (xs[j] == b)):
			break
		if xs[i] == a:
			a += 1
			i += 1
		elif xs[i] == b:
			b -= 1
			i += 1
		if xs[j] == a:
			a += 1
			j -= 1
		elif xs[j] == b:
			b -= 1
			j -= 1
	if i >= j:
		print(-1)
	else:
		print(i + 1, j + 1)


for _ in range(int(input())):
	len = int(input())
	a = list(map(int, input().split()))
	al = 0
	bl = 1
	au = len - 1
	bu = len
	c = False
	while al < au:
		if a[al] == bl:
			al += 1
			bl += 1
		elif a[al] == bu:
			al += 1
			bu -= 1
		elif a[au] == bl:
			au -= 1
			bl += 1
		elif a[au] == bu:
			au -= 1
			bu -= 1
		else:
			c = True
			break
	if c:
		print(str(al + 1) + ' ' + str(au + 1))
	else:
		print('-1')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(i, j) = (0, n - 1)
	(minn, maxx) = (1, n)
	while i < j:
		if minn == maxx:
			print(-1)
			break
		if a[i] == minn:
			i += 1
			minn += 1
		elif a[i] == maxx:
			i += 1
			maxx -= 1
		if a[j] == minn:
			j -= 1
			minn += 1
		elif a[j] == maxx:
			j -= 1
			maxx -= 1
		if (a[i] != minn and a[i] != maxx) and (a[j] != minn and a[j] != maxx):
			print(i + 1, j + 1)
			break
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i1 = 0
	i2 = n - 1
	mx = n
	mn = 1
	while i2 - i1 > 2:
		if a[i1] not in {mn, mx} and a[i2] not in {mn, mx}:
			print(i1 + 1, i2 + 1)
			break
		else:
			if a[i1] == mx:
				mx -= 1
				i1 += 1
			elif a[i1] == mn:
				mn += 1
				i1 += 1
			if a[i2] == mx:
				mx -= 1
				i2 -= 1
			elif a[i2] == mn:
				mn += 1
				i2 -= 1
	else:
		print(-1)


import sys

def read(func=int):
	return func(sys.stdin.readline().strip())

def read_array(func=int):
	return list(map(func, read(str).split()))
t = read()
for _ in range(t):
	n = read()
	A = read_array()
	(mx, mn) = (n, 1)
	l = 0
	r = n - 1
	while l <= r:
		if A[l] == mx:
			l += 1
			mx -= 1
		elif A[l] == mn:
			l += 1
			mn += 1
		elif A[r] == mx:
			r -= 1
			mx -= 1
		elif A[r] == mn:
			r -= 1
			mn += 1
		else:
			break
	if l <= r:
		print(l + 1, r + 1)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	left = 0
	right = n - 1
	check = sorted(array)
	(Min, Max) = (0, n - 1)
	found = False
	while left < right:
		if array[left] == check[Min]:
			left += 1
			Min += 1
		elif array[left] == check[Max]:
			left += 1
			Max -= 1
		elif array[right] == check[Min]:
			right -= 1
			Min += 1
		elif array[right] == check[Max]:
			right -= 1
			Max -= 1
		else:
			found = True
			break
	if found:
		print(left + 1, right + 1)
	else:
		print(-1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	l = len(a)
	(x, y) = (0, l - 1)
	(maxi, mini) = (l, 1)
	while y - x >= 3:
		if a[x] == maxi or a[x] == mini:
			if a[x] == maxi:
				maxi -= 1
			else:
				mini += 1
			x += 1
		elif a[y] == maxi or a[y] == mini:
			if a[y] == maxi:
				maxi -= 1
			else:
				mini += 1
			y -= 1
		else:
			break
	if y - x < 3:
		print(-1)
	else:
		print(x + 1, y + 1)


for _ in range(int(input())):
	length = int(input())
	arr = list(map(int, input().split()))
	min_arr = 1
	max_arr = length
	l = 0
	r = length - 1
	while l < r:
		if min_arr != arr[l] and max_arr != arr[r] and (min_arr != arr[r]) and (max_arr != arr[l]):
			break
		if min_arr == arr[l]:
			l += 1
			min_arr += 1
		if max_arr == arr[l]:
			l += 1
			max_arr -= 1
		if max_arr == arr[r]:
			r -= 1
			max_arr -= 1
		if min_arr == arr[r]:
			r -= 1
			min_arr += 1
	if l >= r:
		print('-1')
	else:
		print(l + 1, r + 1)


import math
k = int(input())
for q in range(k):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = n - 1
	i = 1
	j = n
	flag = 0
	while l < r:
		if a[l] == i or a[l] == j:
			if a[l] == i:
				i += 1
			if a[l] == j:
				j -= 1
			l += 1
		elif a[r] == i or a[r] == j:
			if a[r] == i:
				i += 1
			if a[r] == j:
				j -= 1
			r -= 1
		else:
			print(l + 1, end=' ')
			print(r + 1)
			flag = 1
			break
	if flag == 0:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	elements = [int(x) for x in input().split()]
	sortedElements = list(range(1, n + 1))
	(l, r) = (0, n - 1)
	(first, last) = (0, n - 1)
	while first < last:
		if elements[l] == sortedElements[first]:
			first += 1
			l += 1
		elif elements[l] == sortedElements[last]:
			last -= 1
			l += 1
		elif elements[r] == sortedElements[first]:
			first += 1
			r -= 1
		elif elements[r] == sortedElements[last]:
			last -= 1
			r -= 1
		else:
			break
	if l < r:
		print(l + 1, r + 1)
	else:
		print(-1)


import math

def pow(a, b):
	if b == 0:
		return 1
	elif b == 1:
		return a
	else:
		temp = pow(a, b // 2)
		temp = temp * temp
		if b % 2 == 1:
			temp = temp * a
		return temp
t = int(input())
for _ in range(0, t):
	n = int(input())
	list1 = [int(num) for num in input().split()]
	l = 0
	r = n - 1
	min1 = 1
	max1 = n
	flag = 0
	while l < r:
		if list1[l] == min1:
			l += 1
			min1 += 1
		if list1[l] == max1:
			l += 1
			max1 -= 1
		if list1[r] == min1:
			r -= 1
			min1 += 1
		if list1[r] == max1:
			r -= 1
			max1 -= 1
		if list1[l] != min1 and list1[l] != max1 and (list1[r] != max1) and (list1[r] != min1):
			flag = 1
			break
	if flag == 0 or l >= r:
		print(-1)
	else:
		print(f'{l + 1} {r + 1}')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = input().split(' ')
	arr = [int(x) for x in arr]
	largest = n
	smallest = 1
	(l, r) = (0, n - 1)
	while l < r:
		if arr[l] != largest and arr[l] != smallest and (arr[r] != largest) and (arr[r] != smallest):
			break
		if arr[l] == largest:
			largest -= 1
			l += 1
		elif arr[l] == smallest:
			smallest += 1
			l += 1
		elif arr[r] == smallest:
			smallest += 1
			r -= 1
		else:
			largest -= 1
			r -= 1
	if l < r:
		print(l + 1, r + 1)
	else:
		print(-1)


t = int(input())
for x in range(t):
	n = int(input())
	lst = [int(y) for y in input().split()]
	c1 = 1
	c2 = 0
	l = 0
	u = n - 1
	while True:
		if l >= u - 2:
			print('-1')
			break
		elif lst[l] == c1:
			l += 1
			c1 += 1
		elif lst[l] == n - c2:
			l += 1
			c2 += 1
		elif lst[u] == c1:
			u -= 1
			c1 += 1
		elif lst[u] == n - c2:
			u -= 1
			c2 += 1
		else:
			print(l + 1, '', u + 1)
			break


nbTests = int(input())
for i in range(nbTests):
	n = int(input())
	minToAvoid = 1
	maxToAvoid = n
	(l, r) = (1, n)
	string = input()
	content = list()
	for i in string.split():
		content.append(int(i))
	while True:
		if l == r:
			print(-1)
			break
		if content[l - 1] == minToAvoid:
			l += 1
			minToAvoid += 1
			continue
		if content[l - 1] == maxToAvoid:
			l += 1
			maxToAvoid -= 1
			continue
		if content[r - 1] == minToAvoid:
			r -= 1
			minToAvoid += 1
			continue
		if content[r - 1] == maxToAvoid:
			r -= 1
			maxToAvoid -= 1
			continue
		print(f'{l} {r}')
		break


cases = int(input())
for i in range(0, cases):
	le = int(input())
	a = list(map(int, input().split()))
	sorteda = a.copy()
	sorteda.sort()
	sortedl = 0
	sortedr = len(a) - 1
	l = 0
	r = len(a) - 1
	mflag = 0
	while l < r:
		flag = True
		if a[l] == sorteda[sortedl]:
			flag = False
			l += 1
			sortedl += 1
		elif a[l] == sorteda[sortedr]:
			flag = False
			l += 1
			sortedr -= 1
		if a[r] == sorteda[sortedl]:
			flag = False
			r -= 1
			sortedl += 1
		elif a[r] == sorteda[sortedr]:
			flag = False
			r -= 1
			sortedr -= 1
		if flag == True:
			print(l + 1, r + 1)
			mflag = 1
			break
	if mflag == 0:
		print(-1)


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	x = 1
	y = n
	l = 0
	r = n - 1
	while l < r:
		if x != a[l] and y != a[r] and (x != a[r]) and (y != a[l]):
			break
		if x == a[l]:
			l += 1
			x += 1
		if y == a[l]:
			l += 1
			y -= 1
		if y == a[r]:
			r -= 1
			y -= 1
		if a[r] == x:
			r -= 1
			x += 1
	if l >= r:
		print(-1)
	else:
		print(l + 1, r + 1)
	t -= 1


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 3:
		print(-1)
		continue
	x = 1
	y = n
	ans = -1
	i = 0
	j = n - 1
	while i < j:
		if (a[i] != x and a[j] != y) and (a[i] != y and a[j] != x):
			print(i + 1, j + 1)
			ans = 999
			break
		elif a[i] == x and a[j] == y:
			x += 1
			y -= 1
			i += 1
			j -= 1
		elif a[i] == y and a[j] == x:
			x += 1
			y -= 1
			i += 1
			j -= 1
		elif a[i] == x:
			x += 1
			i += 1
		elif a[j] == x:
			j -= 1
			x += 1
		elif a[i] == y:
			y -= 1
			i += 1
		elif a[j] == y:
			j -= 1
			y -= 1
	if ans == -1:
		print(-1)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	ans = None
	curr = 1
	first = 1
	second = int(n)
	while i < j:
		temp = set([a[i], a[j]])
		if first not in temp and second not in temp:
			ans = (i + 1, j + 1)
			break
		else:
			if a[i] == first:
				first += 1
				i += 1
			if a[j] == first:
				first += 1
				j -= 1
			if a[i] == second:
				second -= 1
				i += 1
			if a[j] == second:
				second -= 1
				j -= 1
	if ans:
		print(*ans)
	else:
		print(-1)


def dora_and_search(n, arr):
	(l, r) = (0, n - 1)
	(mn, mx) = (1, n)
	while l <= r:
		if arr[l] == mn:
			l += 1
			mn += 1
		elif arr[l] == mx:
			l += 1
			mx -= 1
		elif arr[r] == mn:
			r -= 1
			mn += 1
		elif arr[r] == mx:
			r -= 1
			mx -= 1
		else:
			break
	if l <= r:
		print(l + 1, r + 1)
	else:
		print(-1)
t = eval(input())
for _ in range(t):
	n = eval(input())
	arr = list(map(int, input().split()))
	dora_and_search(n, arr)


t = int(input())

def validsublist(l):
	i = 0
	j = len(l) - 1
	k = i
	h = j
	while j - i + 1 > 3:
		if l[i] != k + 1 and l[i] != h + 1 and (l[j] != k + 1) and (l[j] != h + 1):
			print(i + 1, j + 1)
			return False
		elif l[i] == k + 1 and l[j] != h + 1:
			i += 1
			k += 1
		elif l[j] == h + 1 and l[i] != k + 1:
			j -= 1
			h -= 1
		elif l[j] == k + 1 and l[i] != h + 1:
			j -= 1
			k += 1
		elif l[i] == h + 1 and l[j] != k + 1:
			i += 1
			h -= 1
		else:
			i += 1
			k += 1
			j -= 1
			h -= 1
	return True
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	k = validsublist(x)
	if k:
		print(-1)


k = int(input())
res = []
while k > 0:
	n = int(input())
	temp = input().split(' ')
	arr = []
	for num in temp:
		arr.append(int(num))
	(left, right) = (0, len(arr) - 1)
	cur_min = 1
	cur_max = len(arr)
	while left < right:
		if arr[left] != cur_min and arr[left] != cur_max and (arr[right] != cur_min) and (arr[right] != cur_max):
			break
		if arr[left] == cur_min:
			cur_min += 1
			left += 1
		if arr[left] == cur_max:
			cur_max -= 1
			left += 1
		if arr[right] == cur_min:
			cur_min += 1
			right -= 1
		if arr[right] == cur_max:
			cur_max -= 1
			right -= 1
	if left >= right:
		res.append((-1, -1))
	else:
		res.append((left + 1, right + 1))
	k -= 1
for (x, y) in res:
	if x == -1:
		print(-1)
	else:
		print(x, y)


for s in [*open(0)][2::2]:
	a = (0, *map(int, s.split()))
	i = k = 1
	j = l = len(a) - 1
	while i < j and (s := ({a[i], a[j]} & {k, l})):
		i += a[i] in s
		j -= a[j] in s
		k += k in s
		l -= l in s
	print(*([-1], [i, j])[i < j])


for _ in range(int(input())):
	n = int(input())
	elements = list(map(int, input().split()))
	(emin, emax) = (1, n)
	ileft = 0
	size = iright = n - 1
	while size > 2 and (elements[ileft] == emax or elements[ileft] == emin or elements[iright] == emax or (elements[iright] == emin)):
		i = 0
		while emax == elements[ileft + i] and size > 2:
			emax -= 1
			i += 1
			size -= 1
		while emin == elements[ileft + i] and size > 2:
			emin += 1
			i += 1
			size -= 1
		if i > 0:
			ileft += i
		j = iright
		while emax == elements[j] and size > 2:
			emax -= 1
			j -= 1
			size -= 1
		while emin == elements[j] and size > 2:
			emin += 1
			j -= 1
			size -= 1
		if j < iright:
			iright = j
	if size > 2:
		print(ileft + 1, ileft + size + 1)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	flag = 0
	pre = 0
	lst = n - 1
	minn = 1
	maxn = n
	try:
		while flag == 0:
			flag = 1
			if a[pre] == minn:
				pre += 1
				minn += 1
				flag = 0
				continue
			if a[pre] == maxn:
				pre += 1
				maxn -= 1
				flag = 0
				continue
			if a[lst] == minn:
				lst -= 1
				minn += 1
				flag = 0
				continue
			if a[lst] == maxn:
				lst -= 1
				maxn -= 1
				flag = 0
				continue
	except:
		print('-1')
		continue
	print(pre + 1, lst + 1)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	perm = [int(x) for x in input().split()]
	positions = [-1 for x in range(n)]
	for j in range(n):
		positions[perm[j] - 1] = j
	zac = 0
	kon = n - 1
	mx = n
	mn = 1
	while zac < kon and (perm[zac] == mx or perm[kon] == mx or perm[zac] == mn or (perm[kon] == mn)):
		if perm[zac] == mx:
			mx -= 1
			zac += 1
		elif perm[kon] == mx:
			mx -= 1
			kon -= 1
		elif perm[zac] == mn:
			mn += 1
			zac += 1
		elif perm[kon] == mn:
			mn += 1
			kon -= 1
	if zac < kon:
		print(str(zac + 1) + ' ' + str(kon + 1))
	else:
		print(-1)


import math
T = int(input(''))
for i in range(T):
	n = int(input())
	str1 = input()
	l1 = [int(c) for c in str1.split()]
	a = 0
	b = len(l1) - 1
	minVal = 1
	maxVal = len(l1)
	flag = 0
	while a != b and b - a > 1:
		if l1[a] == minVal or l1[a] == maxVal or l1[b] == minVal or (l1[b] == maxVal):
			if l1[a] == minVal:
				minVal += 1
				a += 1
			elif l1[a] == maxVal:
				maxVal -= 1
				a += 1
			if l1[b] == minVal:
				minVal += 1
				b -= 1
			elif l1[b] == maxVal:
				maxVal -= 1
				b -= 1
		else:
			flag = 1
			break
	if flag == 0:
		print(-1)
	else:
		print(a + 1, b + 1)


for nnm in range(int(input(''))):
	n = int(input(''))
	k = [int(x) for x in input('').split(' ')]
	initial = [1, n]
	trip = True
	idx1 = 0
	idx2 = n - 1
	while trip:
		if idx1 > n - 1 or idx2 < 0 or idx1 >= idx2:
			print(-1)
			trip = False
			break
		(a1, a2) = (k[idx1], k[idx2])
		if a1 not in initial and a2 not in initial:
			print(idx1 + 1, idx2 + 1)
			trip = False
			break
		else:
			if a1 == initial[0]:
				initial[0] += 1
				idx1 += 1
			if a1 == initial[1]:
				initial[1] -= 1
				idx1 += 1
			if a2 == initial[0]:
				initial[0] += 1
				idx2 -= 1
			if a2 == initial[1]:
				initial[1] -= 1
				idx2 -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = sorted(a)
	l = 0
	r = n - 1
	ls = 0
	rs = n - 1
	while ls < rs:
		c = False
		while l < len(a) and ls < rs and (a[l] == s[ls]):
			c = True
			ls += 1
			l += 1
		while r >= 0 and ls < rs and (a[r] == s[ls]):
			c = True
			ls += 1
			r -= 1
		while l < len(a) and ls < rs and (a[l] == s[rs]):
			c = True
			rs -= 1
			l += 1
		while r >= 0 and ls < rs and (a[r] == s[rs]):
			c = True
			rs -= 1
			r -= 1
		if not c:
			break
	if l < r:
		print(l + 1, r + 1)
	else:
		print(-1)


import heapq
iter = int(input())
for _ in range(iter):
	n = int(input())
	a = list(map(int, input().split(' ')))
	ma = [-i for i in a]
	arr = a.copy()
	l = 0
	r = n - 1
	heapq.heapify(a)
	heapq.heapify(ma)
	while l <= r:
		if arr[l] == -ma[0] or arr[l] == a[0]:
			if arr[l] == -ma[0]:
				heapq.heappop(ma)
			else:
				heapq.heappop(a)
			l += 1
		elif arr[r] == -ma[0] or arr[r] == a[0]:
			if arr[r] == -ma[0]:
				heapq.heappop(ma)
			else:
				heapq.heappop(a)
			r -= 1
		else:
			break
	if l > r:
		print(-1)
	else:
		print(f'{l + 1} {r + 1}')


from functools import lru_cache
from cmath import inf
from itertools import accumulate
import sys
import bisect
import threading
from collections import Counter
import heapq

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(s):
	min_h = [j for (i, j) in enumerate(s)]
	max_h = [-j for (i, j) in enumerate(s)]
	heapq.heapify(min_h)
	heapq.heapify(max_h)
	(l, r) = (0, len(s) - 1)
	while l < r:
		if s[l] == min_h[0] or s[l] == -max_h[0]:
			heapq.heappop(min_h) if s[l] == min_h[0] else heapq.heappop(max_h)
			l += 1
		elif s[r] == min_h[0] or s[r] == -max_h[0]:
			heapq.heappop(min_h) if s[r] == min_h[0] else heapq.heappop(max_h)
			r -= 1
		else:
			return print(l + 1, r + 1)
	print(-1)

def main():
	for _ in range(inp()):
		inp()
		solve(inlt())
threading.stack_size(1 << 27)
sys.setrecursionlimit(1 << 30)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


T = int(input())
for t in range(0, T):
	n = int(input())
	a = list(map(int, input().split(' ')))
	ptr1 = 0
	ptr2 = n - 1
	l = 0
	r = n - 1
	mini = 1
	maxi = n
	flag = 0
	while ptr1 != ptr2 and ptr1 < n and (ptr2 > -1):
		if a[ptr1] != mini and a[ptr1] != maxi and (a[ptr2] != mini) and (a[ptr2] != maxi):
			l = ptr1
			r = ptr2
			flag = 1
			break
		else:
			if a[ptr1] == mini or a[ptr1] == maxi:
				if a[ptr1] == mini:
					mini += 1
				else:
					maxi -= 1
				ptr1 += 1
			if a[ptr2] == mini or a[ptr2] == maxi:
				if a[ptr2] == mini:
					mini += 1
				else:
					maxi -= 1
				ptr2 -= 1
	if flag == 0:
		print(-1)
	else:
		print(l + 1, r + 1)


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(a, n):
	if n == 3:
		return [-1]
	d = {x: i + 1 for (i, x) in enumerate(a)}
	(l, r) = (1, n)
	(min_a, max_a) = (1, n)
	while l < r:
		if min(a[l - 1], a[r - 1]) != min_a and max(a[l - 1], a[r - 1]) != max_a:
			return [l, r]
		if min(a[l - 1], a[r - 1]) == min_a and max(a[l - 1], a[r - 1]) == max_a:
			l += 1
			r -= 1
			min_a += 1
			max_a -= 1
			continue
		if min(a[l - 1], a[r - 1]) == min_a:
			if a[l - 1] == min_a:
				l += 1
			else:
				r -= 1
			min_a += 1
		if max(a[l - 1], a[r - 1]) == max_a:
			if a[l - 1] == max_a:
				l += 1
			else:
				r -= 1
			max_a -= 1
	return [-1]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(' '.join(map(str, solve(a, n))))