The King of Berland Polycarp LXXXIV has $n$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $n$ other kingdoms as well.

So Polycarp LXXXIV has enumerated his daughters from $1$ to $n$ and the kingdoms from $1$ to $n$. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry.

Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.

For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the $n$-th daughter.

For example, let there be $4$ daughters and kingdoms, the lists daughters have are $[2, 3]$, $[1, 2]$, $[3, 4]$, $[3]$, respectively.

In that case daughter $1$ marries the prince of kingdom $2$, daughter $2$ marries the prince of kingdom $1$, daughter $3$ marries the prince of kingdom $3$, leaving daughter $4$ nobody to marry to.

Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list.

Polycarp LXXXIV wants to increase the number of married couples.

Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it.

If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.

For your and our convenience you are asked to answer $t$ independent test cases.


-----Input-----

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

Then $t$ test cases follow.

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of daughters and the number of kingdoms.

Each of the next $n$ lines contains the description of each daughter's list. The first integer $k$ ($0 \le k \le n$) is the number of entries in the $i$-th daughter's list. After that $k$ distinct integers follow $g_i[1], g_i[2], \dots, g_i[k]$ ($1 \le g_i[j] \le n$) — the indices of the kingdoms in the list in the increasing order ($g_i[1] < g_i[2] < \dots < g_i[k]$).

It's guaranteed that the total number of daughters over all test cases does not exceed $10^5$.

It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed $10^5$.


-----Output-----

For each test case print the answer to it.

Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers — the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list.

If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.

Otherwise the only line should contain one word "OPTIMAL".


-----Examples-----

Input
5
4
2 2 3
2 1 2
2 3 4
1 3
2
0
0
3
3 1 2 3
3 1 2 3
3 1 2 3
1
1 1
4
1 1
1 2
1 3
1 4
Output
IMPROVE
4 4
IMPROVE
1 1
OPTIMAL
OPTIMAL
OPTIMAL


-----Note-----

The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.

In the second test case any new entry will increase the number of marriages from $0$ to $1$.

In the third and the fourth test cases there is no way to add an entry.

In the fifth test case there is no way to change the marriages by adding any entry.

Source: codeforces | Difficulty: EASY
Tags: Complete search

Graph algorithms

Greedy algorithms


Solutions:
n = int(input())
for i in range(n):
	k = int(input())
	arr = [[] for i in range(k + 1)]
	prince = [0 for i in range(k + 1)]
	girl = [0 for i in range(k + 1)]
	for j in range(1, k + 1):
		arr[j] = list(map(int, input().split()))
	for i1 in range(1, k + 1):
		look = 1
		for j1 in range(1, len(arr[i1])):
			if prince[arr[i1][j1]] == 0 and look == 1:
				prince[arr[i1][j1]] = 1
				girl[i1] = 1
				look = 0
	imp = 0
	for i1 in range(1, k + 1):
		if prince[i1] == 0 and imp == 0:
			for j1 in range(1, k + 1):
				if girl[j1] == 0 and imp == 0:
					print('IMPROVE')
					print(j1, i1)
					imp = 1
	if imp == 0:
		print('OPTIMAL')


n = int(input())
for i in range(n):
	y = int(input())
	f = [0] * y
	g = [0] * y
	p = []
	for j in range(y):
		p.append(list(map(int, input().split()))[1:])
	for j in range(1, y + 1):
		for q in p[j - 1]:
			if f[q - 1] == 0:
				f[q - 1] = 1
				g[j - 1] = 1
				break
	if sum(g) == y:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(g.index(0) + 1, f.index(0) + 1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	daughters = []
	for i in range(n):
		daughters.append(list(map(int, input().split()))[1:])
	wishList = []
	for i in daughters:
		temp = {}
		for j in i:
			temp[j] = 0
		wishList.append(temp)
	kings = {}
	unmarried = []
	for i in range(1, n + 1):
		kings[i] = 0
	for (b, i) in enumerate(daughters):
		flag = 0
		for j in i:
			if kings[j] == 0:
				kings[j] = 1
				flag = 1
				n -= 1
				break
		if flag == 0:
			unmarried.append(b + 1)
	flag = 0
	if n == 0:
		print('OPTIMAL')
		continue
	else:
		for i in kings.keys():
			if kings[i] == 0:
				for j in unmarried:
					if i not in wishList[j - 1]:
						flag = 1
						print('IMPROVE')
						print(j, i)
						break
			if flag:
				break
	if flag == 0:
		print('OPTIMAL')


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	b = [False] * (n + 1)
	p = [0] * (n + 1)
	for i in range(n):
		for j in sorted(l[i][1:]):
			if not b[j]:
				p[i + 1] = j
				b[j] = True
				break
	if False in b[1:]:
		print('IMPROVE')
		print(p[1:].index(0) + 1, end=' ')
		print(b[1:].index(False) + 1)
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	A = []
	for i in range(n):
		(a, *b) = map(int, input().split())
		A += [[x - 1 for x in b]]
	(B, C) = ([False] * n, [False] * n)
	for i in range(n):
		for j in A[i]:
			if not C[j]:
				B[i] = True
				C[j] = True
				break
	(x, y) = (-1, -1)
	for i in range(n):
		if not B[i]:
			x = i + 1
			for j in range(n):
				if not C[j]:
					y = j + 1
					break
			break
	if x == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(f'{x} {y}')


for _ in range(int(input())):
	n = int(input())
	l = []
	t = [0] * n
	nt = -1
	s = 0
	for i in range(n):
		l = list(map(int, input().split()))
		c = 1
		check = s
		while c < l[0] + 1:
			if t[l[c] - 1] == 0:
				t[l[c] - 1] = 1
				s += 1
				break
			else:
				c += 1
		if s == check and nt == -1:
			nt = i
	if s == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if t[i] == 0:
				print(nt + 1, i + 1)
				break


import sys

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
	n = read_int()
	l = []
	ps = [False] * n
	for i in range(n):
		a = read_int_line()
		l.append(a[1:])
	f = False
	psi = -1
	p = [False] * n
	for i in range(n):
		j = 0
		while j < len(l[i]) and ps[l[i][j] - 1]:
			j += 1
		if j >= len(l[i]):
			f = True
			psi = i + 1
		else:
			p[i] = True
			ps[l[i][j] - 1] = True
	if f:
		psi = -1
		for i in range(n):
			if not p[i]:
				psi = i + 1
		ki = -1
		for i in range(n):
			if not ps[i]:
				ki = i + 1
		if ki == -1 or psi == -1:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(psi, ki)
	else:
		print('OPTIMAL')


for i in range(int(input())):
	n = int(input())
	daughter = [0] * n
	prince = [0] * n
	for i in range(n):
		dlist = list(map(int, input().split()))
		m = dlist[0]
		for j in range(1, m + 1):
			if prince[dlist[j] - 1] == 0:
				daughter[i] = 1
				prince[dlist[j] - 1] = 1
				break
	if 0 in daughter:
		print('IMPROVE')
		print(daughter.index(0) + 1, prince.index(0) + 1)
	else:
		print('OPTIMAL')


def inp():
	n = input()
	A = []
	for i in range(int(n)):
		try:
			d = input().split()
			A.append([int(d[0]), int(d[1])])
		except:
			pass
	return A

def A():
	A = inp()
	for (n, k) in A:
		if k > n:
			print('NO')
		elif n % 2 ^ k % 2:
			print('NO')
		else:
			print('YES')

def inp():
	t = int(input())
	for i in range(t):
		d = int(input())
		dots = []
		for j in range(d):
			A = list(map(int, input().split()))[1:]
			dots.append(A)
		B(d, dots)

def B(dot, A):
	pr = [1] * dot
	dot = [1] * dot
	for (i, dt) in enumerate(A):
		for j in dt:
			if pr[j - 1]:
				pr[j - 1] = 0
				dot[i] = 0
				break
	if sum(pr):
		for (j, p) in enumerate(pr):
			if p:
				for (i, d) in enumerate(dot):
					if d:
						print('IMPROVE\n', i + 1, j + 1)
						return
	print('OPTIMAL')
inp()


for _ in range(int(input())):
	n = int(input())
	prince = [0] * n
	princes = [0] * n
	choice = []
	for q in range(n):
		ar = list(map(int, input().split()))
		if ar[0] == 0:
			choice.append([])
		else:
			b = ar[1:]
			b.sort()
			choice.append(b)
	left = []
	for i in range(n):
		for j in choice[i]:
			if prince[j - 1] == 0:
				prince[j - 1] = 1
				princes[i - 1] = 1
				break
		if princes[i - 1] == 0:
			left.append(i)
	if len(left) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		ans1 = left[0] + 1
		ans2 = -1
		for i in range(n):
			if prince[i] == 0:
				ans2 = i + 1
				break
		print(ans1, ans2)


import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
	f = iter(open('B.txt').readlines())

	def input():
		return next(f).strip()
else:
	input = lambda : sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
import itertools
ops = 0
for _ in range(int(input())):
	n = int(input())
	used = set()
	d = {i: list(map(int, input().split()))[1:] for i in range(1, n + 1)}
	q = {}
	for i in range(1, n + 1):
		for j in d[i]:
			if j not in used:
				used.add(j)
				q[i] = j
				break
	u = set(range(1, n + 1)) - set(q)
	v = set(range(1, n + 1)) - used
	if u and v:
		print('IMPROVE')
		print(u.pop(), v.pop())
	else:
		print('OPTIMAL')


import io
import os
import sys
from io import BytesIO
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = int(input())
	g = [list(map(int, input().split()))[1:] for i in range(n)]
	(kingdom_left, left) = (set(range(1, n + 1)), list(range(1, n + 1)))
	for _ in range(n):
		for cur in g[_]:
			if cur in kingdom_left:
				kingdom_left.remove(cur)
				break
		else:
			left.append(_ + 1)
	if len(left) and len(kingdom_left):
		print('IMPROVE\n{} {}'.format(left[-1], kingdom_left.pop()))
	else:
		print('OPTIMAL')
t = int(input())
for _ in range(t):
	solve()


import sys
t = int(sys.stdin.readline().rstrip())

def main():
	for _ in range(t):
		n = int(sys.stdin.readline().rstrip())
		G = []
		for _ in range(n):
			(g, *a) = map(int, sys.stdin.readline().split())
			G.append(a)
		fixed = set()
		no = []
		for i in range(n):
			cand = G[i]
			for c in cand:
				if c in fixed:
					continue
				fixed.add(c)
				break
			else:
				no.append(i + 1)
		if not no:
			yield 'OPTIMAL'
		else:
			yield 'IMPROVE'
			to = min(set(range(1, n + 1)) - fixed)
			da = no[0]
			yield '{0} {1}'.format(da, to)
ans = main()
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
t = int(input())
for r in range(t):
	n = int(input())
	prince = {}
	princesses = {}
	l = [0]
	for i in range(n):
		tt = list(map(int, input().split()))
		x = []
		if tt[0] != 0:
			x = tt[1:]
		l.append(x)
	for i in range(n):
		prince[i + 1] = 0
		princesses[i + 1] = 0
	count = 0
	current = n
	for i in range(1, n + 1):
		for j in l[i]:
			if prince[j] == 0:
				prince[j] = 1
				princesses[i] = 1
				count += 1
				break
	flag = True
	for i in prince:
		if prince[i] == 0:
			flag = False
			break
	if flag == True:
		print('OPTIMAL')
	else:
		ans = []
		unmarried_prince = []
		for i in prince:
			if prince[i] == 0:
				unmarried_prince.append(i)
		unmarried_princess = {}
		for i in princesses:
			if princesses[i] == 0:
				unmarried_princess[i] = princesses[i]
		for i in unmarried_prince:
			for j in unmarried_princess:
				try:
					if unmarried_princess[j][i] >= 0:
						pass
				except:
					ans = [j, i]
					flag = True
					break
			if flag == True:
				break
		if flag == True:
			print('IMPROVE')
			print(str(ans[0]) + ' ' + str(ans[1]))
		else:
			print('OPTIMAL')


from sys import stdin
input = stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	A = []
	for j in range(n):
		p = [int(j) for j in input().split()]
		if p[0] > 0:
			A.append(p[1:])
		else:
			A.append([])
	pk = set()
	left = None
	for (x, j) in enumerate(A):
		for k in j:
			if k not in pk:
				pk.add(k)
				break
		else:
			if left == None:
				left = x + 1
	if left:
		print('IMPROVE')
		a = left
		for j in range(1, n + 1):
			if j not in pk:
				print(a, j)
				break
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	l = [0] * n
	count = 0
	times = 0
	index = 0
	for j in range(n):
		a = list(map(int, input().split()))
		for k in range(1, a[0] + 2):
			if k == a[0] + 1:
				if times == 0:
					count = 1
					index = j
					times += 1
				break
			elif l[a[k] - 1] == 0:
				l[a[k] - 1] = 1
				break
	if count == 0:
		print('OPTIMAL')
	else:
		for i in range(0, n):
			if l[i] == 0:
				king = i
				break
		print('IMPROVE')
		print(str(index + 1) + ' ' + str(king + 1))


from sys import *
from bisect import bisect_left
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	d = dict()
	for i in range(1, n + 1):
		d[i] = 0
	l = []
	for i in range(n):
		li = list(map(int, input().split()))
		l.append(li)
	un = []
	for i in range(n):
		f = 0
		for j in range(1, len(l[i])):
			if d[l[i][j]] == 0:
				d[l[i][j]] = 1
				f = 1
				break
		if f == 0:
			un.append(i)
	if len(un) == 0:
		print('OPTIMAL')
		continue
	prince = []
	for i in d:
		if d[i] == 0:
			prince.append(i)
	else:
		flag = 0
		for i in prince:
			if flag == 1:
				break
			for j in range(len(un)):
				if bisect_left(l[un[j]], i, 0, len(l[un[j]])) <= len(l[un[j]]):
					flag = 1
					ans = [un[j] + 1, i]
					break
		if flag == 1:
			print('IMPROVE')
			print(ans[0], ans[1])
		else:
			print('OPTIMAL')


for i_ in range(int(input())):
	n = int(input())
	bb = [0] * (n + 1)
	imp = -1
	for i in range(n):
		l = list(map(int, input().split()))
		can = 0
		for j in range(1, len(l)):
			if bb[l[j]] == 0:
				bb[l[j]] = 1
				can = 1
				break
		if can == 1:
			continue
		else:
			imp = i + 1
	if imp == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if bb[i] == 0:
				print('IMPROVE')
				print(imp, i)
				break


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		s = [int(v) for v in input().split()]
		a.append(s)
	j = 0
	p = [0] * n
	u = []
	for j in range(n):
		k = 1
		f = 0
		while k <= a[j][0]:
			if p[a[j][k] - 1] == 0:
				p[a[j][k] - 1] = 1
				f = 1
				break
			k = k + 1
		if f == 0:
			u.append(j)
	if u == []:
		print('OPTIMAL')
	else:
		j = 0
		while j < n:
			if p[j] == 0:
				x = j + 1
				break
			j = j + 1
		print('IMPROVE')
		print(u[0] + 1, x)


t = int(input())
for i in range(t):
	n = int(input())
	prin = [0] * n
	bad = -1
	for j in range(n):
		g = list(map(int, input().split()))
		married = 0
		k = 0
		while k < g[0] and married == 0:
			k += 1
			if prin[g[k] - 1] == 0:
				prin[g[k] - 1] = 1
				married = 1
		if married == 0:
			bad = j
	if bad == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		ind = n
		foo = 0
		while ind > 0 and foo == 0:
			ind -= 1
			if prin[ind] == 0:
				foo = 1
		print(bad + 1, ind + 1)


from sys import stdin

def read():
	x = stdin.readline().rstrip()
	return [int(i) for i in x.split()]
t = int(input())
for t0 in range(t):
	n = int(input())
	single_girls = set()
	single_boys = set((i + 1 for i in range(n)))
	for n0 in range(1, n + 1):
		A = read()
		As = set(A)
		if A[0] != 0:
			f = True
			counter = 1
			while f:
				boy = A[counter]
				if boy in single_boys:
					f = False
					single_boys.discard(boy)
				counter += 1
				if counter > A[0]:
					if f:
						f = False
						single_girls.add(n0)
		else:
			single_girls.add(n0)
	if single_girls:
		girl = list(single_girls)[0]
		boy = list(single_boys)[0]
		print('IMPROVE')
		print(girl, boy)
	else:
		print('OPTIMAL')


import math

def ii():
	return int(input())

def ill():
	return input().split(' ')

def ili():
	return [int(i) for i in input().split(' ')]

def ilis():
	return (int(i) for i in input().split(' '))

def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def extgcd(a, b, x=0, y=0):
	if b == 0:
		return (a, 1, 0)
	(d, m, n) = extgcd(b, a % b, x, y)
	return (d, n, m - a // b * n)

def main():
	T = ii()
	for t in range(T):
		n = ii()
		vis = [False for _ in range(2 * n)]
		unpaired = []
		for g in range(n):
			line = ili()
			flag = False
			for b in range(1, line[0] + 1):
				if not vis[n + line[b] - 1]:
					vis[g] = True
					vis[n + line[b] - 1] = True
					flag = True
					break
			if not flag:
				line[0] = g
				unpaired.append(line)
		if len(unpaired) == 0:
			print('OPTIMAL')
			continue
		flag = False
		b = -1
		for i in range(2 * n - 1, n - 1, -1):
			if not vis[i]:
				b = i - n
		for l in unpaired:
			if len(l) - 1 >= n:
				break
			if not (b + 1 in l[1:] or vis[b + n]):
				flag = True
				print('IMPROVE\n{} {}'.format(l[0] + 1, b + 1))
				break
			if flag:
				break
		if not flag:
			print('OPTIMAL')
main()


from sys import stdout, stdin
write = stdout.write
read = stdin.readline
t = int(read())
for _ in range(t):
	n = int(read())
	prince_married = [False] * n
	unmarried_princess = None
	for i in range(n):
		married = False
		princes = read().split()[1:]
		for p in princes:
			p = int(p) - 1
			if not prince_married[p]:
				prince_married[p] = True
				married = True
				break
		if not married:
			unmarried_princess = i
	if unmarried_princess is None:
		write('OPTIMAL\n')
	else:
		last_prince = prince_married.index(False)
		write('IMPROVE\n')
		write(f'{unmarried_princess + 1} {last_prince + 1}\n')


t = int(input())
otvet = []
for h in range(t):
	n = int(input())
	g1 = []
	g = [0] * n
	for i in range(n):
		g1.append(input().split())
		g1[i].pop(0)
		g[i] = [int(item) for item in g1[i]]
	prince = [0] * n
	nope = []
	for i in range(n):
		for k in range(len(g[i])):
			x = g[i][k]
			if prince[x - 1] == 0:
				prince[x - 1] = 1
				break
		else:
			nope.append(i)
	if 0 in prince:
		otvet.append([nope[0] + 1, prince.index(0) + 1])
	else:
		otvet.append([-1, -1])
for i in range(t):
	if otvet[i] == [-1, -1]:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(otvet[i][0], otvet[i][1])


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	v = [0] * n
	k = 0
	for i in range(n):
		a = list(filter(None, list(map(lambda x: int(x) if not v[int(x) - 1] else None, input().split()))[1:][::-1]))
		if a:
			v[a[-1] - 1] = 1
		else:
			k = i + 1
	if k:
		print('IMPROVE\n')
		print(str(k) + ' ' + str(v.index(0) + 1) + '\n')
	else:
		print('OPTIMAL\n')


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
for _ in range(int(input())):
	n = int(input())
	prince = set(range(1, n + 1))
	princess = set(range(1, n + 1))
	princess_list = [[] for _ in range(n + 1)]
	for i in range(n):
		k = list(map(int, input().split()))[1:]
		princess_list[i + 1] = k
		if k:
			for j in k:
				if j in prince:
					prince.remove(j)
					princess.remove(i + 1)
					break
	tmp = False
	for pr1 in princess:
		for pr2 in prince:
			if pr2 in princess_list[pr1]:
				continue
			else:
				print(f'IMPROVE\n')
				print(f'{pr1} {pr2}\n')
				tmp = True
				break
		if tmp:
			break
	else:
		print('OPTIMAL\n')


t = int(input())
from collections import defaultdict
from sys import stdin, stdout
for i in range(t):
	n = int(input())
	l = []
	for j in range(n):
		lx = list(map(int, stdin.readline().split()))
		lx.pop(0)
		l.append(lx)
	d = defaultdict(int)
	d1 = defaultdict(int)
	l1 = range(1, n + 1)
	ans = True
	for j in range(n):
		for k in l[j]:
			if d[k] == 0:
				d[k] += 1
				d1[j + 1] += 1
				break
		if d1[j + 1] == 0:
			x = j + 1
			ans = False
	for j in range(1, n + 1):
		if d[j] == 0:
			print('IMPROVE')
			print(x, j)
			ans = False
			break
	if ans == True:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	total = set(range(n))
	matched_left = set()
	matched_right = set()
	for i in range(n):
		a = [int(x) - 1 for x in input().split()]
		k = a.pop(0) + 1
		for j in range(k):
			if a[0] in matched_right:
				a.pop(0)
			else:
				matched_left.add(i)
				matched_right.add(a[0])
				break
	remaining_left = total - matched_left
	remaining_right = total - matched_right
	if remaining_left and remaining_right:
		print('IMPROVE')
		print(remaining_left.pop() + 1, remaining_right.pop() + 1)
	else:
		print('OPTIMAL')


import collections
import sys
input = sys.stdin.readline
t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	m = collections.defaultdict()
	total = 0
	v_p = [False] * n
	v_k = [False] * n
	for i in range(n):
		g = list(map(int, input().split()))
		total += g[0]
		for j in range(1, g[0] + 1):
			if i not in m and (not v_k[g[j] - 1]):
				m[i] = g[j]
				v_p[i] = v_k[g[j] - 1] = True
				break
	if len(m) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		p = k = 0
		for i in range(n):
			if not v_p[i]:
				p = i
				break
		for i in range(n):
			if not v_k[i]:
				k = i
				break
		print(p + 1, k + 1)


import sys

def answer(n, g):
	available_princes_set = {i for i in range(1, n + 1, 1)}
	for i in range(n):
		if g[i][0] == 0:
			print('IMPROVE')
			print(i + 1, min(available_princes_set))
			return
		for k in range(1, g[i][0] + 1):
			if g[i][k] in available_princes_set:
				available_princes_set.remove(g[i][k])
				break
			elif k == g[i][0]:
				print('IMPROVE')
				print(i + 1, min(available_princes_set))
				return
	print('OPTIMAL')
	return

def answer2(n, g):
	available_princes_set = {i for i in range(1, n + 1, 1)}
	match = [False] * n
	for i in range(n):
		for k in range(1, g[i][0] + 1):
			if g[i][k] in available_princes_set:
				available_princes_set.remove(g[i][k])
				match[i] = True
				break
	for i in range(n):
		if match[i] == False:
			print('IMPROVE')
			print(i + 1, min(available_princes_set))
			return
	print('OPTIMAL')
	return

def main():
	t = int(input())
	while t:
		n = int(sys.stdin.readline().rstrip())
		g = [0] * n
		for j in range(n):
			g[j] = [int(i) for i in sys.stdin.readline().split()]
		answer2(n, g)
		t -= 1
	return
main()


import sys
from math import *
from collections import defaultdict
from queue import deque
from heapq import heappush, heappop
lines = [line.strip() for line in sys.stdin.readlines()]
t = int(lines[0])
cur = 1
for tt in range(t):
	n = int(lines[cur])
	avail = [True for i in range(n + 1)]
	a = -1
	for i in range(1, 1 + n):
		xs = list(map(int, lines[cur + i].split()))[1:]
		found = False
		for x in xs:
			if avail[x]:
				avail[x] = False
				found = True
				break
		if a == -1 and (not found):
			a = i
	if a == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if avail[i]:
				print('IMPROVE\n%d %d' % (a, i))
				break
	cur += 1 + n


t = int(input())
for _ in range(t):
	n = int(input())
	used = [0] * (n + 1)
	d_nr = -1
	for i in range(n):
		d = list(map(int, input().split()))[1:]
		paired = 0
		for k in d:
			if used[k] == 0:
				used[k] = 1
				paired = 1
				break
		if not paired:
			d_nr = i
	if d_nr == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for ii in range(1, n + 1):
			if used[ii] == 0:
				sol = ii
		print('{} {}'.format(d_nr + 1, sol))


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
for _testcases_ in range(int(input())):
	n = int(input())
	ans = -1
	visited = [False] * (n + 1)
	for i in range(1, n + 1):
		li = get_list()[1:]
		for l in li:
			if not visited[l]:
				visited[l] = True
				break
		else:
			ans = i
	if ans != -1:
		v = visited.index(False, 1, n + 1)
	print('IMPROVE\n{} {}'.format(ans, v) if ans != -1 else 'OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	vis = [False] * n
	t = set((i for i in range(n)))
	for i in range(n):
		arr = list(map(int, input().split()))[1:]
		for j in arr:
			if not vis[j - 1]:
				vis[j - 1] = True
				t.discard(i)
				break
	if t and False in vis:
		print('IMPROVE')
		print(list(t)[0] + 1, vis.index(False) + 1)
	else:
		print('OPTIMAL')


I = input
for _ in [0] * int(I()):
	s = {*range(1, int(I()) + 1)}
	for i in [*s]:
		try:
			s -= {min({*map(int, I().split()[1:])} & s)}
		except:
			k = i
	print(s and f'IMPROVE {k} {s.pop()}' or 'OPTIMAL')


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
for _ in range(II()):
	(f, m) = (set(), set())
	n = II()
	for i in range(1, n + 1):
		f.add(i)
		for v in LI()[1:]:
			if v not in m:
				m.add(v)
				f.remove(i)
				break
	if f:
		for v in range(1, n + 1):
			if v not in m:
				print('IMPROVE')
				print(f.pop(), v)
				break
	else:
		print('OPTIMAL')


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		ls = [0] * (n + 1)
		princess = [[]]
		c = 0
		un_prin = -1
		for kkk in range(1, n + 1):
			arr = list(map(int, stdin.readline().split()))
			picked = False
			for (i, x) in enumerate(arr):
				if i == 0:
					continue
				if ls[x] == 0:
					c += 1
					ls[x] = 1
					picked = True
					break
			if picked is False:
				un_prin = kkk
		if un_prin != -1:
			for x in range(1, n + 1):
				if ls[x] == 0:
					stdout.write('IMPROVE\n' + str(un_prin) + ' ' + str(x) + '\n')
					break
		else:
			stdout.write('OPTIMAL\n')
main()


T = int(input())
n = [0] * T
m = [0] * T
ns = [0] * T
k = [0] * T
for t in range(T):
	n[t] = int(input())
	ns[t] = [0] * n[t]
	k[t] = [0] * n[t]
	for i in range(n[t]):
		ns[t][i] = [int(i) for i in input().split(' ')]
		k[t][i] = ns[t][i].pop(0)

def ans(n, k, ns):
	pri = [1] * n
	dtpr = [1] * n
	s = [-1] * n
	for i in range(n):
		for j in range(k[i]):
			if pri[ns[i][j] - 1] and s[i] == 0:
				s[i] = ns[i][j]
				break
			if pri[ns[i][j] - 1]:
				pri[ns[i][j] - 1] = 0
				dtpr[i] = 0
				s[i] = 0
	if 1 not in pri:
		return 'OPTIMAL'
	return str('IMPROVE\n' + str(dtpr.index(1) + 1) + ' ' + str(pri.index(1) + 1))
for t in range(T):
	print(ans(n[t], k[t], ns[t]))


t = int(input())
while t:
	n = int(input())
	prince = [0 for i in range(n)]
	princess = [0 for i in range(n)]
	for i in range(n):
		tmp = [int(x) for x in input().split()]
		lst = [tmp[x] for x in range(1, len(tmp))]
		if len(lst) == 0:
			continue
		cg = min(lst)
		while True:
			if len(lst) == 0:
				break
			cg = min(lst)
			if prince[cg - 1] == 0:
				break
			lst.remove(cg)
		if prince[cg - 1] == 0:
			prince[cg - 1] = 1
			princess[i] = 1
	if sum(princess) == n:
		print('OPTIMAL')
	else:
		a = princess.index(0) + 1
		b = prince.index(0) + 1
		print('IMPROVE')
		print(a, b)
	t = t - 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	info = [list(map(int, input().split())) for i in range(n)]
	set_ = set()
	flag = -1
	for i in range(n):
		pos = 1
		while True:
			if pos == len(info[i]):
				flag = i
				break
			if info[i][pos] in set_:
				pos += 1
			else:
				set_.add(info[i][pos])
				break
	if flag >= 0:
		print('IMPROVE')
		new_set = set(info[flag][1:])
		for i in range(1, n + 1):
			if i not in set_ and i not in new_set:
				print(flag + 1, i)
				break
	else:
		print('OPTIMAL')


T = int(input())
for _ in range(T):
	(n, p) = (int(input()), [])
	for _ in range(n):
		p.append(list(map(int, input().split())))
	vis = [0] * (n + 1)
	(g, b) = (0, 0)
	for i in range(n):
		for u in p[i][1:]:
			if not vis[u]:
				vis[u] = 1
				break
		else:
			g = i + 1
	for i in range(1, n + 1):
		if not vis[i]:
			b = i
			break
	if g and b:
		print('IMPROVE')
		print(g, b)
	else:
		print('OPTIMAL')


from sys import stdin, stdout

def cout(x):
	print(x, end=' ')
	return
t = int(input())
for _i in range(t):
	n = int(input())
	ya = [False for i in range(n)]
	cual = -1
	for i in range(n):
		v = [int(x) - 1 for x in stdin.readline().split()]
		for x in range(1, len(v) + 1):
			if x == len(v):
				if cual == -1:
					cual = i
				break
			elif not ya[v[x]]:
				ya[v[x]] = True
				break
	if cual == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		p = 0
		for i in range(len(ya)):
			if not ya[i]:
				p = i
				break
		print(str(cual + 1) + ' ' + str(p + 1))


from __future__ import division, print_function

def main():
	for _ in range(int(input())):
		d = int(input())
		options = []
		for i in range(d):
			l1 = list(map(int, input().split()))
			l1 = l1[1:]
			l1.sort()
			options.append(l1)
		taken = {}
		unmarried = []
		for i in range(d):
			j = 0
			while j < len(options[i]) and options[i][j] in taken:
				j += 1
			if j == len(options[i]):
				unmarried.append(i)
			else:
				taken[options[i][j]] = 1
		if unmarried:
			print('IMPROVE')
			x = unmarried[0]
			for i in range(1, d + 1):
				if i not in taken:
					break
			print(x + 1, i)
		else:
			print('OPTIMAL')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	g = []
	for i in range(n):
		A = list(map(int, input().split()))
		k = A[0]
		B = A[1:k + 1]
		B = [b - 1 for b in B]
		g.append(B)
	visit = [-1] * n
	mar = [-1] * n
	used = set()
	for i in range(n):
		for v in g[i]:
			if visit[v] == -1:
				mar[i] = v
				visit[v] = 0
				used.add(v)
				break
	notused = set(range(n)) - used
	id = -1
	for i in range(n):
		if mar[i] == -1:
			id = i
	if id != -1:
		notused = set(range(n)) - used
		p = list(notused)
		p.sort()
		q = p[-1]
		print('IMPROVE')
		print(id + 1, q + 1)
	else:
		print('OPTIMAL')


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	n = read_int()
	kingdoms = [False] * n
	princes = [False] * n
	matches = 0
	for i in range(n):
		(k, *choices) = read_ints()
		for c in choices:
			if not kingdoms[c - 1]:
				kingdoms[c - 1] = True
				princes[i] = True
				matches += 1
				break
	if matches == n:
		return 'OPTIMAL'
	return 'IMPROVE\n{} {}'.format(princes.index(False) + 1, kingdoms.index(False) + 1)
T = read_int()
for _ in range(T):
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	a = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		a[i].pop(0)
	p = [False for i in range(n)]
	pr = [False for i in range(n)]
	for pos in range(n):
		for j in a[pos]:
			if not pr[j - 1]:
				p[pos] = True
				pr[j - 1] = True
				break
	if min(p):
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(p.index(False) + 1, pr.index(False) + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	info = []
	for _ in range(n):
		info.append([int(x) for x in input().split()][1:])
	free = [True] * n
	alone = 0
	for (i, p) in enumerate(info):
		for k in p:
			if free[k - 1]:
				free[k - 1] = False
				break
		else:
			alone = i + 1
	if not alone:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		k = free.index(True) + 1
		print(alone, k)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	dc = {}
	girl = {}
	for __ in range(n):
		a = list(map(int, input().split()))
		n1 = len(a)
		for i in range(1, n1):
			if dc.get(a[i], 0) == 0:
				girl[__] = 1
				dc[a[i]] = 1
				break
	ind = -1
	for k in range(n):
		if girl.get(k, 0) == 0:
			ind = k
			break
	if ind != -1:
		for i in range(1, n + 1):
			if dc.get(i, 0) == 0:
				print('IMPROVE')
				print(ind + 1, i)
				break
	else:
		print('OPTIMAL')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	used = [False for i in range(n)]
	v = -1
	for i in range(n):
		l = [int(x) - 1 for x in stdin.readline().split()][1:]
		for j in l:
			if used[j] == False:
				used[j] = True
				break
		else:
			v = i
	if v == -1:
		stdout.write('OPTIMAL\n')
	else:
		u = used.index(False)
		stdout.write('IMPROVE\n' + str(v + 1) + ' ' + str(u + 1) + '\n')


from sys import stdin, stdout
from math import *
import itertools

def wr(text):
	stdout.write(str(text))

def war(a):
	stdout.write(' '.join(map(str, a)) + '\n')

def wrl(text):
	stdout.write(str(text) + '\n')
cin = list(stdin)
ci = 1
for zz in range(int(cin[0])):
	n = int(cin[ci])
	ci += 1
	ts = set([i + 1 for i in range(n)])
	np = []
	for x in range(n):
		t = [int(i) for i in cin[ci].split()][1:]
		ci += 1
		h = True
		for i in t:
			if i in ts:
				h = False
				ts.remove(i)
				break
		if h:
			np.append(x + 1)
	if len(np) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(np[0], list(ts)[0])


t = int(input())
for test in range(t):
	n = int(input())
	l = []
	l.append(0)
	for i in range(1, n + 1):
		l.append(i)
	dd = []
	pp = []
	for i in range(n):
		pp.append([int(x) for x in input().split()])
	for i in range(n):
		p = pp[i]
		f = 0
		for j in range(p[0]):
			if l[p[j + 1]] != 0:
				l[p[j + 1]] = 0
				f = 1
				break
		if f == 0:
			dd.append(i + 1)
	o = max(l)
	if o == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(dd[0], o)


t = int(input())
for test in range(t):
	n = int(input())
	k = []
	ass = {}
	kkk = set()
	dd = []
	for i in range(n):
		p = [int(x) for x in input().split()]
		if p[0] == 0:
			k.append([])
		else:
			k.append(sorted(p[1:]))
		f = 0
		for king in k[i]:
			if king not in ass:
				ass[king] = []
				ass[king].append(i + 1)
				kkk.add(king)
				f = 1
				break
		if f == 0:
			dd.append(i + 1)
	l = set()
	for i in range(1, n + 1):
		l.add(i)
	left = list(l - kkk)
	o = 0
	if len(left) == 0:
		print('OPTIMAL')
		continue
	else:
		print('IMPROVE')
		print(dd[0], left[0])


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	data = input().rstrip().split()
	k = int(data[0])

	def find_min(arr, free):
		for a in arr:
			if free[a - 1] == 1:
				return a
		return None
	for _ in range(k):
		daughter = None
		data = input().rstrip().split()
		n = int(data[0])
		ps = []
		for i in range(n):
			data = input().rstrip().split()
			u = int(data[0])
			d = [int(e) for e in data[1:]]
			ps.append(d)
		free = [1] * n
		for i in range(1, n + 1):
			a = find_min(ps[i - 1], free)
			if a is None:
				daughter = i
			else:
				free[a - 1] = 0
		if daughter is None:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			for j in range(1, n + 1):
				if free[j - 1] == 1:
					break
			print(str(daughter) + ' ' + str(j))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	married_d = [False] * n
	married_p = [False] * n
	for i in range(n):
		A = list(map(int, input().split()))
		for a in A[1:]:
			if not married_p[a - 1]:
				married_p[a - 1] = True
				married_d[i] = True
				break
	d = -1
	for i in range(n):
		if not married_d[i]:
			d = i
			break
	p = -1
	for i in range(n):
		if not married_p[i]:
			p = i
			break
	if d >= 0 and p >= 0:
		print('IMPROVE')
		print(d + 1, p + 1)
	else:
		print('OPTIMAL')


R = lambda : map(int, input().split())
t = int(input())

def solve(free, daug):
	for x in daug:
		if free[x]:
			free[x] = False
			return False
	return True
for _ in range(t):
	n = int(input())
	free = [True] * (n + 1)
	free[0] = False
	found = 0
	for i in range(n):
		pref = list(R())[1:]
		if solve(free, pref):
			if found == 0:
				found = i + 1
	if found == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(found, free.index(True))


for _ in range(int(input())):
	n = int(input())
	prince = [False] * (n + 1)
	princess = [False] * (n + 1)
	count = 0
	for i in range(n):
		li = list(map(int, input().split()))
		for j in li[1:]:
			if prince[j] == False:
				prince[j] = True
				princess[i + 1] = True
				count += 1
				break
	flag = 0
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for j in range(1, n + 1):
			if flag == 1:
				break
			elif princess[j] == False:
				print(j, end=' ')
				for k in range(1, n + 1):
					if prince[k] == False:
						print(k)
						flag = 1
						break


for ii in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		temp = list(map(int, input().split()))
		arr.append(temp[1:])
	princess = [0] * (n + 1)
	prince = [0] * (n + 1)
	prince[0] = 1
	princess[0] = 1
	for i in range(n):
		for j in arr[i]:
			if not prince[j]:
				prince[j] = 1
				princess[i + 1] = 1
				break
	ok = 1
	for i in range(n + 1):
		if not princess[i]:
			ok = 0
			for j in range(n + 1):
				if not prince[j]:
					print('IMPROVE')
					print(i, j)
					break
			if not ok:
				break
		if not ok:
			break
	if ok:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	p = [0] * (n + 1)
	flag = -1
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		if l[0] != 0:
			for j in l[1:]:
				if p[j] == 0:
					p[j] = 1
					break
			else:
				flag = i
		else:
			flag = i
	if flag == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		p = p[1:].index(0)
		print(flag, p + 1)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = [0 for _ in range(n)]
	b = [0 for _ in range(n)]
	for i in range(n):
		x = [int(p) for p in stdin.readline().split()]
		for j in range(1, x[0] + 1):
			if a[x[j] - 1] == 0:
				a[x[j] - 1] = 1
				b[i] = 1
				break
	if a.count(0) > 0 and b.count(0) > 0:
		print('IMPROVE')
		print(b.index(0) + 1, a.index(0) + 1)
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	daughters = list()
	freeKingdoms = [0] * n
	freeDaughter = 0
	for j in range(n):
		for k in [int(x) for x in input().split()][1:]:
			if freeKingdoms[k - 1]:
				continue
			freeKingdoms[k - 1] = 1
			break
		else:
			freeDaughter = j + 1
	if freeDaughter == 0:
		print('OPTIMAL')
	else:
		for j in range(n):
			if not freeKingdoms[j]:
				print('IMPROVE\n' + str(freeDaughter) + ' ' + str(j + 1))
				break
		else:
			print('OPTIMAL')


from sys import stdin, stdout
for t in range(int(stdin.readline())):
	n = int(stdin.readline())
	married = [0] * (n + 1)
	l = []
	for i in range(n):
		lst = list(map(int, stdin.readline().split()))
		for val in lst[1:]:
			if not married[val]:
				married[val] = 1
				break
		else:
			l += [i + 1]
	if not l:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		for i in range(1, n + 1):
			if not married[i]:
				stdout.write(str(l[0]) + ' ' + str(i) + '\n')
				break


from sys import stdin
t = int(input())
for p in range(t):
	n = int(stdin.readline())
	nums = [list(map(int, stdin.readline().split()))[1:] for l in range(n)]
	seen = set(range(1, n + 1))
	married = set(range(1, n + 1))
	for i in range(len(nums)):
		for j in nums[i]:
			if j in seen:
				seen.remove(j)
				married.remove(i + 1)
				break
	if seen:
		print('IMPROVE')
		print(married.pop(), seen.pop())
	else:
		print('OPTIMAL')


for case in range(int(input())):
	n = int(input())
	final_set = set()
	possiblites = []
	princes_possible = [-1] * (n + 1)
	princess_possible = [False] * (n + 1)
	n_flag = False
	for i in range(n):
		temp = [int(x) for x in input().split()]
		k = temp[0]
		princes = temp[1:]
		for x in princes:
			if princes_possible[x] == -1:
				princes_possible[x] = i + 1
				princess_possible[i + 1] = True
				break
	princess = -1
	for i in range(1, n + 1):
		if princess_possible[i] == False:
			princess = i
			break
	if princess == -1:
		print('OPTIMAL')
	else:
		prince = -1
		for i in range(1, n + 1):
			if princes_possible[i] == -1:
				prince = i
				break
		print('IMPROVE')
		print(princess, prince)


t = int(input())
for _ in range(t):
	n = int(input())
	kingdom = [0 for __ in range(n)]
	princess = [0 for __ in range(n)]
	for j in range(n):
		tem = list(map(int, input().split()))[1:]
		mi = 10 ** 6
		for i in tem:
			if i < mi and kingdom[i - 1] == 0:
				mi = i
		if mi != 10 ** 6:
			kingdom[mi - 1] = 1
			princess[j] = 1
	if sum(princess) != n:
		print('IMPROVE')
		print(princess.index(0) + 1, kingdom.index(0) + 1)
	else:
		print('OPTIMAL')


n = int(input())
for i in range(n):
	empty = []
	t = int(input())
	found = [0] * t
	for j in range(t):
		preference = list(map(int, input().split()))[1:]
		flag = True
		for k in preference:
			if found[k - 1] == 0:
				found[k - 1] = 1
				flag = False
				break
		if flag == True:
			empty += [j]
	if len(empty) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(t):
			if found[i] == 0:
				print(str(empty[0] + 1) + ' ' + str(i + 1))
				break


from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(T):
	(n, p) = (int(input()), [])
	for _ in range(n):
		p.append(list(map(int, input().split())))
	vis = [0] * (n + 1)
	(g, b) = (0, 0)
	for i in range(n):
		for u in p[i][1:]:
			if not vis[u]:
				vis[u] = 1
				break
		else:
			g = i + 1
	for i in range(1, n + 1):
		if not vis[i]:
			b = i
			break
	if g and b:
		print('IMPROVE')
		print(g, b)
	else:
		print('OPTIMAL')


t = int(input())
for k1 in range(t):
	n = int(input())
	tab = [0 for i in range(n + 1)]
	tab[0] = 2
	ki = []
	for d1 in range(n):
		r2 = 0
		s = input().split()
		k = int(s[0])
		if k == 0:
			ki.append(d1 + 1)
		else:
			for i in range(1, k + 1):
				if tab[int(s[i])] == 0:
					tab[int(s[i])] = 1
					r2 = 1
					break
			if r2 == 0:
				ki.append(d1 + 1)
	if len(ki) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ki[0], end=' ')
		i1 = tab.index(min(tab))
		print(i1)


def more_couples(test):
	princess = test[1]
	n = test[0]
	if n == 0:
		return ('OPTIMAL', ())
	ledger = [False for x in range(n)]
	empty = 0
	for p in princess:
		if len(p) == 0:
			empty += 1
			continue
		current_min = min(p)
		while len(p) > 0 and ledger[current_min - 1]:
			p.remove(current_min)
			if len(p) > 0:
				current_min = min(p)
		ledger[current_min - 1] = True
	available = 0
	for i in range(len(ledger)):
		if not ledger[i]:
			available = i + 1
			break
	for i in range(len(princess)):
		if len(princess[i]) == 0:
			return ('IMPROVE', (i + 1, available))
	return ('OPTIMAL', ())
t = int(input())
tests = []
for _ in range(t):
	n = int(input())
	princes = []
	for _ in range(n):
		princes.append(list(map(int, input().split()))[1:])
	tests.append((n, princes))
for test in tests:
	res = more_couples(test)
	print(res[0])
	if res[0] == 'IMPROVE':
		print(f'{res[1][0]} {res[1][1]}')


def f(n, a):
	d = {}
	m = []
	for i in range(n):
		for j in a[i][1:]:
			if j not in d:
				d[j] = i + 1
				break
		if len(d) < i + 1:
			m.append(i + 1)
	if len(d) == n:
		return 'OPTIMAL'
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in d:
				for j in m:
					if i not in a[j - 1][1:]:
						return str(j) + ' ' + str(i)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = []
		for _ in range(n):
			a.append([int(i) for i in input().split()])
		print(f(n, a))
main()


for _ in range(int(input())):
	n = int(input())
	taken = [0] * (n + 1)
	married = [0] * (n + 1)
	taken[0] = 1
	married[0] = 1
	for i in range(1, n + 1):
		a = list(map(int, input().split()))
		l = len(a)
		for j in range(1, l):
			if taken[a[j]] != 1:
				taken[a[j]] = 1
				married[i] = 1
				break
	marry = ''
	marry = marry.join(str(married))
	if '0' in marry:
		print('IMPROVE')
		print(married.index(0), end=' ')
		print(taken.index(0))
	else:
		print('OPTIMAL')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	g = defaultdict(list)
	for i in range(n):
		l = li()[1:]
		for j in l:
			g[i + 1].append(j)
	empty = set([*range(1, n + 1)])
	visited = set([*range(1, n + 1)])
	for i in g:
		picked = 0
		for j in g[i]:
			if j in visited:
				visited.remove(j)
				picked = 1
				break
		if picked:
			empty.remove(i)
	if len(visited):
		print('IMPROVE')
		print(empty.pop(), visited.pop())
	else:
		print('OPTIMAL')


t = int(input())
d = {}
p = {}
for i in range(t):
	n = int(input())
	for j in range(n):
		d[j + 1] = 1
		p[j + 1] = 1
	y = 0
	for j in range(n):
		g = list(map(int, input().split()))
		if g[0] == 0:
			y = 1
		else:
			x = 0
			for k in range(1, g[0] + 1):
				if d[g[k]] == 1:
					d[g[k]] = 0
					x = 1
					p[j + 1] = 0
					break
			if x == 0:
				y = 1
	if y == 1:
		print('IMPROVE')
		for i in range(1, n + 1):
			if p[i] == 1:
				print(i, end=' ')
				break
		for i in range(1, n + 1):
			if d[i] == 1:
				print(i)
				break
	else:
		print('OPTIMAL')


import sys

def printMissing(arr, low, high):
	s = set(arr)
	for x in range(low, high + 1):
		if x not in s:
			print(x, end=' ')
			break
input = sys.stdin.readline
T = int(input())
for t in range(T):
	N = int(input())
	prin = dict()
	for n in range(N):
		a = [int(i) for i in input().split(' ')]
		for i in range(1, a[0] + 1):
			try:
				prin[a[i]]
			except:
				prin[a[i]] = n + 1
				break
	if len(prin) < N:
		print('IMPROVE')
		printMissing(prin.values(), 1, N)
		printMissing(prin.keys(), 1, N)
		print('')
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [False] * n
	l2 = [False] * n
	for i in range(n):
		l = list(map(int, input().split()))[1:]
		for j in l:
			if not l2[j - 1]:
				l1[i] = True
				l2[j - 1] = True
				break
	f1 = 0
	f2 = 0
	s = ' '
	for i in range(n):
		if f1 == 0 and (not l1[i]):
			f1 = 1
			s = str(i + 1) + s
		if f2 == 0 and (not l2[i]):
			f2 = 1
			s = s + str(i + 1)
		if f1 == 1 and f2 == 1:
			break
	if f1 == 1 and f2 == 1:
		print('IMPROVE')
		print(s)
	else:
		print('OPTIMAL')


for i in range(int(input())):
	num = int(input())
	p = [0] * num
	tot = []
	for j in range(num):
		a = list(map(int, input().split()))
		k = a.pop(0)
		bo = False
		for z in a:
			if p[z - 1] == 0:
				p[z - 1] = 1
				bo = True
				break
		if bo == False:
			tot.append(j + 1)
	if tot == []:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(tot[0], p.index(0) + 1)


from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a1 = [int(i) for i in input().split()]
		a1 = a1[1:]
		a1 = deque(a1)
		a.append(a1)
	married = [0] * (n + 1)
	unmarried = -1
	for i in range(n):
		while len(a[i]) >= 1 and married[a[i][0]] == 1:
			a[i].popleft()
		if len(a[i]) >= 1:
			married[a[i][0]] = 1
		if len(a[i]) == 0 and unmarried == -1:
			unmarried = i + 1
	ans = married.count(0)
	if ans > 1:
		pos = married[1:].index(0) + 1
	if ans > 1:
		print('IMPROVE')
		print(unmarried, pos)
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	l = [0] * n
	g = [0] * (n + 1)
	who = 0
	for i in range(n):
		l[i] = [int(_) for _ in input().split()]
	for i in range(n):
		flg = False
		for j in range(1, l[i][0] + 1):
			if g[l[i][j]] == 0:
				g[l[i][j]] += 1
				flg = True
				break
		if not flg:
			if who == 0:
				who = i + 1
	if who > 0:
		ans = 0
		for j in range(1, n + 1):
			if g[j] == 0:
				ans = j
				break
		print('IMPROVE')
		print(who, ans)
	else:
		print('OPTIMAL')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	d = [0] * n
	f = 0
	for i in range(n):
		arr = list(map(int, input().split()))
		m = 10 ** 5
		flag = False
		for k in range(1, arr[0] + 1):
			if d[arr[k] - 1] == 0:
				d[arr[k] - 1] = 1
				flag = True
				break
		if flag == False:
			f = i + 1
	if f != 0:
		print('IMPROVE')
		print(f, d.index(0) + 1)
	else:
		print('OPTIMAL')


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():

	def unusei():
		for i in range(n):
			if itoj[i] == -1:
				return i
		return -1

	def unusej():
		for j in range(n):
			if jtoi[j] == -1:
				return j
		return -1
	q = II()
	for _ in range(q):
		n = II()
		itoj = [-1] * n
		jtoi = [-1] * n
		for i in range(n):
			gg = LI()
			for j in gg[1:]:
				j -= 1
				if jtoi[j] == -1:
					itoj[i] = j
					jtoi[j] = i
					break
		ui = unusei()
		if ui == -1:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			uj = unusej()
			print(ui + 1, uj + 1)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	used = [False for i in range(n)]
	v = -1
	for i in range(n):
		l = [int(x) - 1 for x in input().split()][1:]
		for j in l:
			if not used[j]:
				used[j] = True
				break
		else:
			v = i
	if v == -1:
		print('OPTIMAL')
	else:
		u = used.index(False)
		print('IMPROVE')
		print(v + 1, u + 1)


for i in range(int(input())):
	n = int(input())
	check = [0 for k in range(n)]
	married = [0 for k in range(n)]
	count = 0
	(y, z) = (0, 0)
	for k in range(n):
		flag = 0
		A = [int(j) for j in input().split()]
		for l in range(1, A[0] + 1):
			if check[A[l] - 1] == 0:
				check[A[l] - 1] = 1
				married[k] = 1
				count += 1
				flag = 1
				break
		if flag == 0:
			y = k + 1
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(y, check.index(0) + 1)


I = input
for _ in [0] * int(I()):
	r = range(1, int(I()) + 1)
	s = {*r}
	for i in r:
		try:
			s -= {min({*map(int, I().split()[1:])} & s)}
		except:
			k = i
	print(f'IMPROVE {k} {s.pop()}' if s else 'OPTIMAL')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for case in range(int(input())):
	n = int(input())
	final_set = set()
	possiblites = []
	princes_possible = [-1] * (n + 1)
	princess_possible = [False] * (n + 1)
	n_flag = False
	for i in range(n):
		temp = [int(x) for x in input().split()]
		k = temp[0]
		princes = temp[1:]
		for x in princes:
			if princes_possible[x] == -1:
				princes_possible[x] = i + 1
				princess_possible[i + 1] = True
				break
	princess = -1
	for i in range(1, n + 1):
		if princess_possible[i] == False:
			princess = i
			break
	if princess == -1:
		print('OPTIMAL')
	else:
		prince = -1
		for i in range(1, n + 1):
			if princes_possible[i] == -1:
				prince = i
				break
		print('IMPROVE')
		print(princess, prince)


t = int(input())
for _ in range(t):
	k = int(input())
	one = -1
	gens = [False] * (k + 1)
	for j in range(1, k + 1):
		ee = False
		g = list(map(int, input().split()))
		for i in range(1, g[0] + 1):
			if gens[g[i]] is False:
				gens[g[i]] = True
				ee = True
				break
		if not ee:
			one = j
	if one > 0:
		print('IMPROVE')
		o = gens.index(False, 1)
		print('{0} {1}'.format(one, o))
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	g = [0] * n
	bused = [False] * n
	gused = [False] * n
	for i in range(n):
		c = list(map(int, input().split()))
		g[i] = []
		for j in range(c[0]):
			g[i].append(c[j + 1])
	for i in range(n):
		for j in range(len(g[i])):
			if bused[g[i][j] - 1] == False:
				bused[g[i][j] - 1] = True
				gused[i] = True
				break
	k = -1
	for i in range(n):
		if bused[i] == False:
			k = i
			break
	if k != -1:
		for i in range(n):
			if gused[i] == False:
				print('IMPROVE')
				print(i + 1, k + 1)
				return
	print('OPTIMAL')

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


for _ in range(int(input())):
	n = int(input())
	taken = [False] * n
	empty = []
	for i in range(n):
		temp = list(map(int, input().split()))
		flag = False
		for k in temp[1:]:
			if not taken[k - 1]:
				flag = True
				taken[k - 1] = True
				break
		if not flag:
			empty.append(i + 1)
	if empty:
		print('IMPROVE')
		print(empty[0], taken.index(False) + 1)
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	nt = set()
	for i in range(1, n + 1):
		nt.add(i)
	princess = [False for i in range(n)]
	arr = []
	for i in range(n):
		tmp = [int(i) for i in input().split()]
		arr.append(tmp)
	for i in range(n):
		x = arr[i][0]
		for j in range(1, 1 + x):
			if arr[i][j] in nt:
				nt.remove(arr[i][j])
				princess[i] = True
				break
	if len(nt) == 0:
		print('OPTIMAL')
	else:
		x = -1
		for i in range(n):
			if princess[i] == False:
				x = i
				break
		for i in nt:
			pos = i
			break
		print('IMPROVE')
		print(x + 1, pos)


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	n = inp()
	a = []
	q = [0] * n
	w = [0] * n
	for i in range(n):
		b = inlt()
		b = b[1:]
		a.append(b)
	for i in range(len(a)):
		c = 0
		for j in range(len(a[i])):
			if q[a[i][j] - 1] == 0:
				w[i] = i + 1
				q[a[i][j] - 1] = 1
				break
	if 0 in w:
		print('IMPROVE')
		print(w.index(0) + 1, q.index(0) + 1)
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	married = [0 for i in range(n)]
	used = [0 for i in range(n)]
	ans_princess = -1
	for i in range(n):
		g = list(map(int, input().split()))[1:]
		for j in g:
			if used[j - 1] == 0:
				married[i] = 1
				used[j - 1] = 1
				break
		else:
			ans_princess = i
	for i in range(n):
		if used[i] == 0:
			print('IMPROVE')
			print(ans_princess + 1, i + 1)
			break
	else:
		print('OPTIMAL')


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	n = int(input())
	m = [0 for j in range(n)]
	z = -1
	for j in range(n):
		s = 0
		dt = list(map(int, input().split()))
		for k in dt[1:]:
			if m[k - 1] == 0:
				m[k - 1] = j + 1
				s = 1
				break
		if s == 0:
			z = j + 1
	if z == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(z, m.index(0) + 1)


for _ in range(int(input())):
	n = int(input())
	graph = []
	taken = [0] * n
	married = [0] * n
	for i in range(n):
		graph.append(list(map(int, input().split(' '))))
		if graph[i][0] != 0:
			j = 1
			while j <= graph[i][0]:
				if not taken[graph[i][j] - 1]:
					married[i] = 1
					taken[graph[i][j] - 1] = 1
					break
				j += 1
	if taken.count(1) != n:
		print('IMPROVE')
		ind_K = taken.index(0)
		ind_D = married.index(0)
		while ind_D != -1:
			if not graph[ind_D][1:].__contains__(ind_K + 1):
				print(ind_D + 1, ind_K + 1)
				break
			else:
				try:
					ind_D = married[ind_D + 1:].index(0)
				except ValueError:
					ind_D = -1
	else:
		print('OPTIMAL')


from sys import stdin

def solve(graph):
	m = max(map(lambda g: max(g) if len(g) else 0, graph))
	prince = set(range(1, m + 2))
	princess = set()
	for (idx, edges) in enumerate(graph):
		target = prince & edges
		if len(target) == 0:
			princess |= set([idx + 1])
		else:
			prince -= set([min(target)])
	if len(princess) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print('{} {}'.format(min(princess), min(prince)))
	return
input()
for line in stdin:
	n = int(line)
	graph = [set(list(map(int, stdin.readline().split()))[1:]) for _ in range(n)]
	solve(graph)


for _ in range(int(input())):
	n = int(input())
	k = []
	l = []
	s = [0] * n
	for i in range(n):
		lst = list(map(int, input().split()))
		ky = lst[0]
		k.append(ky)
		if len(lst) > 1:
			lst = lst[1:]
			l.append(lst)
		else:
			l.append([0])
	x = []
	for id in range(n):
		f = 0
		while f == 0:
			if len(l[id]) == 0:
				break
			a = min(l[id])
			if a == 0:
				break
			if s[a - 1] == 0:
				f = 2
				s[a - 1] = 1
			l[id].remove(a)
		if f == 0:
			x.append(id + 1)
	if len(x) == 0:
		print('OPTIMAL')
	else:
		for i in range(n):
			if s[i] == 0:
				z = i + 1
				break
		print('IMPROVE')
		print(x[0], z)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	princesse = [list(map(int, sys.stdin.readline().split())) for i in range(n)]
	pris = [False] * n
	palone = -1
	for p in range(n):
		ok = False
		for i in range(1, len(princesse[p])):
			if not pris[princesse[p][i] - 1]:
				ok = True
				pris[princesse[p][i] - 1] = True
				break
		if not ok:
			palone = p
	if palone == -1:
		print('OPTIMAL')
	else:
		for i in range(n):
			if not pris[i]:
				print('IMPROVE')
				print(palone + 1, i + 1)
				break


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	t = I()
	for _ in range(t):
		n = I()
		f = [1] * (n + 1)
		ans = None
		for i in range(1, n + 1):
			g = LI()[1:]
			for j in g:
				if f[j]:
					f[j] = 0
					break
			else:
				if ans == None:
					ans = i
		if ans != None:
			print('IMPROVE')
			for i in range(1, n + 1):
				if f[i]:
					break
			print(ans, i)
		else:
			print('OPTIMAL')
	return
solve()


import sys
input = sys.stdin.readline
from bisect import bisect_left
from sys import stdin, stdout

def main():
	for _ in range(int(input())):
		n = int(input())
		l = [[int(s) for s in input().split()] for i in range(n)]
		visited = [0] * n
		flagg = 0
		ansg = -1
		for i in range(n):
			if l[i][0] == 0:
				ansg = i
				flagg = 1
			else:
				for j in range(1, l[i][0] + 1):
					if visited[l[i][j] - 1] == 0:
						visited[l[i][j] - 1] = 1
						break
				else:
					ansg = i
					flagg = 1
		if flagg == 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			ansb = -1
			for i in range(n):
				if visited[i] == 0:
					ansb = i
					break
			print(ansg + 1, ansb + 1)
main()


t = int(input())
for i in range(t):
	n = int(input())
	x = dict()
	for i in range(n):
		l = list(map(int, input().split()))
		flag = 0
		for j in range(1, len(l)):
			if l[j] in x:
				pass
			else:
				x[l[j]] = 1
				flag = 1
				break
		if flag == 0:
			rock = i + 1
	count = 0
	for i in x.keys():
		count += x[i]
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i in x:
				pass
			else:
				haha = i
				break
		print(rock, haha)


from sys import stderr
t = int(input())
for _ in range(t):
	n = int(input())
	s = set()
	p = n * [False]
	for i in range(n):
		g = list(map(int, input().split()))
		k = g[0]
		g = g[1:]
		for e in g:
			if e not in s:
				p[i] = True
				s.add(e)
				break
	flag = True
	for e in p:
		flag = flag and e
	if flag:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if not p[i]:
				for j in range(n):
					if j + 1 not in s:
						print(i + 1, j + 1)
						break
				break


t = int(input())
for _ in range(t):
	n = int(input())
	v = [0 for i in range(n + 1)]
	miss = n + 1
	for i in range(n):
		l = list(map(int, input().split()))
		while len(l) > 1:
			if v[min(l[1:])] == 1:
				l.remove(min(l[1:]))
			else:
				break
		if len(l) == 1:
			miss = min(miss, i)
			continue
		else:
			v[min(l[1:])] = 1
	flag = 0
	for i in range(1, n + 1):
		if v[i] == 0:
			print('IMPROVE')
			print(miss + 1, i)
			flag = 1
			break
	if flag == 0:
		print('OPTIMAL')


import sys

def I():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LMI():
	return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
t = I()
for _ in range(t):
	n = I()
	G = [None] * n
	for i in range(n):
		(_, *g) = MI()
		G[i] = [x - 1 for x in g]
	k_married = set()
	d_married = set()
	for (d, g) in enumerate(G):
		for k in g:
			if k not in k_married:
				k_married.add(k)
				d_married.add(d)
				break
	if len(k_married) < n:
		print('IMPROVE')
		for i in range(n):
			if i not in d_married:
				print(i + 1, end=' ')
				break
		for i in range(n):
			if i not in k_married:
				print(i + 1)
				break
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

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

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

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	n = getInt()
	a = {}
	res1 = -1
	res2 = -1
	for i in range(n):
		g = getList()
		g.pop(0)
		z = False
		for j in g:
			if j not in a:
				a[j] = 1
				z = True
				break
		if not z and res1 == -1:
			res1 = i + 1
	if res1 == -1:
		print('OPTIMAL')
	else:
		for j in range(1, n + 1):
			if j not in a:
				res2 = j
				break
		print('IMPROVE')
		print(res1, res2)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	pref = []
	for _ in range(n):
		d = list(map(int, input().split()))[1:]
		pref.append(d)
	taken = [False] * n
	first_empty = -1
	for i in range(n):
		for num in pref[i]:
			if not taken[num - 1]:
				taken[num - 1] = True
				break
		else:
			if first_empty == -1:
				first_empty = i + 1
	added = -1
	for (i, prince) in enumerate(taken):
		if not prince:
			added = i + 1
			break
	if added != -1:
		print('IMPROVE')
		print(str(first_empty) + ' ' + str(added))
	else:
		print('OPTIMAL')


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, G):
	match = {}
	unmatchedPrincess = []
	for (princess, edges) in enumerate(G, 1):
		matched = False
		for prince in edges:
			if prince not in match:
				match[prince] = princess
				matched = True
				break
		if not matched:
			unmatchedPrincess.append(princess)
	if unmatchedPrincess:
		for prince in range(1, N + 1):
			if prince not in match:
				return 'IMPROVE\n' + str(unmatchedPrincess[0]) + ' ' + str(prince)
	return 'OPTIMAL'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	G = [[int(x) for x in input().split()][1:] for i in range(N)]
	ans = solve(N, G)
	print(ans)


def main():
	n = int(input())
	prince = set()
	princes = set()
	for i in range(1, n + 1):
		prince.add(i)
	to_change = -1
	for i in range(n):
		lst = list(map(int, input().split()))
		have = False
		for k in lst[1:]:
			if k in prince:
				have = True
				prince.remove(k)
				princes.add(i)
				break
		if not have:
			to_change = i
	if to_change == -1:
		print('OPTIMAL')
		return
	print('IMPROVE')
	print(to_change + 1, min(prince))
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	king = [[0]]
	for i in range(n):
		a = list(map(int, input().split()))
		king.append(a[1:])
	ans = [0] * (n + 1)
	a[0] = 1
	k = 0
	for i in range(1, n + 1):
		flag = 0
		for j in range(len(king[i])):
			l = king[i][j]
			if ans[l] == 0:
				ans[l] = 1
				flag = 1
				break
		if flag == 0:
			k = i
	if ans[1:] == [1] * n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if ans[i] == 0:
				print(k, i)
				break


def go():
	n = int(input())
	m = [[] for _ in range(n)]
	for i in range(n):
		for (j, x) in enumerate(map(int, input().split())):
			if j == 0:
				continue
			m[x - 1].append(i)
	k = [-1] * n
	freex = -1
	for i in range(n):
		for kk in m[i]:
			if k[kk] < 0:
				k[kk] = i
				break
		else:
			freex = i
	if freex != -1:
		for i in range(n):
			if k[i] == -1:
				return f'IMPROVE\n{i + 1} {freex + 1}'
	return 'OPTIMAL'
t = int(input())
ans = []
for _ in range(t):
	ans.append(go())
print('\n'.join(ans))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		KG = [[int(x) for x in input().split()] for _ in range(N)]
		married = set()
		not_married = [0] * N
		count = 0
		memo = -1
		for (ikg, kg) in enumerate(KG):
			for (i, g) in enumerate(kg):
				if i == 0:
					continue
				if g not in married:
					married.add(g)
					not_married[g - 1] = 1
					count += 1
					break
			else:
				memo = ikg + 1
		if count != N:
			x = not_married.index(0)
			print('IMPROVE')
			print(memo, x + 1)
		else:
			print('OPTIMAL')
main()


t = int(input())
for i in range(t):
	n = int(input())
	mat = []
	vis = [0] * n
	st = set()
	for j in range(0, n):
		st.add(j + 1)
	for j in range(n):
		arr = list(map(int, input().split()))
		mat.append(arr)
	for j in range(n):
		for k in range(mat[j][0]):
			if vis[j] == 0:
				if mat[j][k + 1] in st:
					vis[j] = 1
					st.discard(mat[j][k + 1])
			if vis[j] == 1:
				break
	flag = 1
	for j in range(n):
		if vis[j] == 0:
			e = st.pop()
			print('IMPROVE')
			print(j + 1, e)
			flag = 0
			break
	if flag == 1:
		print('OPTIMAL')


for i in range(int(input())):
	n = int(input())
	prince = [0 for i in range(n + 1)]
	ind = -1
	for i in range(n):
		l = list(map(int, input().split()))
		e = l[0]
		l.pop(0)
		f = 0
		for j in range(e):
			if prince[l[j]] == 0:
				prince[l[j]] = 1
				f = 1
				break
		if f == 0 and ind == -1:
			ind = i + 1
	if ind == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if prince[i] == 0:
				print('IMPROVE')
				print(ind, i)
				break


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
for i in range(int(data())):
	n = int(data())
	A = [0] * n
	s = -1
	for j in range(n):
		l = list(mdata())[1:]
		flag = False
		for i in range(len(l)):
			if A[l[i] - 1] == 0:
				A[l[i] - 1] = 1
				flag = True
				break
		if flag == False:
			s = j
	if s != -1:
		print('IMPROVE')
		for j in range(n):
			if A[j] == 0:
				print(s + 1, j + 1)
				break
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	range_n = range(1, int(input()) + 1)
	available_women = set()
	available_men = set()
	for i in range_n:
		available_women.add(i)
		available_men.add(i)
	for woman in range_n:
		wanted_men = input().split()[1:]
		for man in wanted_men:
			man = int(man)
			if man in available_men:
				available_women.remove(woman)
				available_men.remove(man)
				break
	if not available_women:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(f'{next(iter(available_women))} {next(iter(available_men))}')


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

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

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

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

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(lis())
	hashy = {}
	remaining = []
	for i in range(n):
		flag = False
		for j in range(a[i][0]):
			if a[i][j + 1] not in hashy:
				hashy[a[i][j + 1]] = 1
				flag = True
				break
		if not flag:
			remaining.append(i + 1)
	if len(remaining) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(remaining[0], end=' ')
		for j in range(n):
			if j + 1 not in hashy:
				hashy[j + 1] = 1
				print(j + 1)
				break


output = []

def solve(n, daughter):
	prince = set()
	firstfail = -1
	for (i, d) in enumerate(daughter):
		success = False
		for p in d:
			if p not in prince:
				prince.add(p)
				success = True
				break
		if firstfail == -1 and (not success):
			firstfail = i + 1
	if firstfail == -1:
		output.append('OPTIMAL')
	else:
		c = next((p for p in range(1, n + 1) if p not in prince))
		output.append('IMPROVE')
		output.append('{0} {1}'.format(firstfail, c))
t = int(input())
for _ in range(t):
	n = int(input())
	d = []
	for _ in range(n):
		d.append(list(map(int, input().split()[1:])))
	solve(n, d)
for line in output:
	print(line)


n = int(input())
li_final = []
for i in range(n):
	n1 = int(input())
	li_3 = [[int(l) for l in input().split()] for k in range(n1)]
	li_final.append(li_3)
for i in range(n):
	li_1 = li_final[i]
	n1 = len(li_1)
	li_2 = [False] + [True] * (n1 + 1)
	li_3 = [False] * (n1 + 1)
	for k in range(n1):
		for j in range(1, len(li_1[k])):
			if li_2[li_1[k][j]]:
				li_2[li_1[k][j]] = False
				li_3[k + 1] = True
				break
	for l in range(1, n1 + 1):
		if li_3[l] == False:
			print('IMPROVE')
			print(l, li_2.index(True))
			break
	else:
		print('OPTIMAL')


import sys
t = int(input())
for _ in range(t):
	n = int(sys.stdin.readline())
	dList = []
	for _ in range(n):
		a = set(list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))[1:])
		dList += [a]
	princes = set([i for i in range(n)])
	daughter = -1
	for i in range(len(dList)):
		chosenPrince = min(dList[i] & princes, default=-1)
		if chosenPrince >= 0:
			princes.remove(chosenPrince)
		else:
			daughter = i
	if daughter < 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(daughter + 1, 1 + min(princes))


import sys
for q in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	d = []
	p = [1] * (n + 1)
	badd = -1
	for i in range(n):
		d.append([int(j) for j in sys.stdin.readline().split()])
	for i in range(n):
		pr = -1
		for j in range(d[i][0]):
			if p[d[i][j + 1]]:
				pr = d[i][j + 1]
				break
		if pr != -1:
			p[pr] = 0
		else:
			badd = i
	if badd == -1:
		sys.stdout.write('OPTIMAL\n')
	else:
		badp = -1
		for pri in range(1, n + 1):
			if p[pri]:
				badp = pri
				break
		sys.stdout.write(f'IMPROVE\n{badd + 1} {badp}\n')


from sys import stdin, stdout
I = stdin.readline
O = stdout.write
for i_ in range(int(I())):
	n = int(I())
	bb = [0] * (n + 1)
	imp = -1
	for i in range(n):
		l = list(map(int, I().split()))
		can = 0
		for j in range(1, len(l)):
			if bb[l[j]] == 0:
				bb[l[j]] = 1
				can = 1
				break
		if can == 1:
			continue
		else:
			imp = i + 1
	if imp == -1:
		O('OPTIMAL\n')
	else:
		for i in range(1, n + 1):
			if bb[i] == 0:
				O('IMPROVE\n' + str(imp) + ' ' + str(i) + '\n')
				break


for _ in range(int(input())):
	n = int(input())
	remk = [True] * n
	remd = [True] * n
	c = 0
	for j in range(n):
		for i in list(map(int, input().split()))[1:]:
			if remk[i - 1]:
				remk[i - 1] = False
				remd[j] = False
				c += 1
				break
	if c == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		(low, lo) = (0, 0)
		while low < n:
			if remd[low]:
				while not remk[lo]:
					lo += 1
				print(low + 1, lo + 1)
				lo += 1
				break
			low += 1


import sys
input = sys.stdin.readline
print = sys.stdout.write
for _ in range(int(input())):
	n = int(input())
	d = dict()
	arr = [0] * (n + 1)
	temp = None
	for j in range(n):
		k = list(map(int, input().split()))
		for i in k[1:]:
			if arr[i] == 0:
				arr[i] = 1
				break
		else:
			temp = j + 1
	if temp:
		for (i, j) in enumerate(arr[1:n + 1]):
			if j == 0:
				print('IMPROVE' + '\n')
				print(str(temp) + ' ' + str(i + 1) + '\n')
				break
	else:
		print('OPTIMAL' + '\n')


for _ in range(int(input())):
	n = int(input())
	kds = [0] * n
	free_pr = -1
	for i_princess in range(n):
		(k, *wishlist) = list(map(int, input().split(' ')))
		check_free = i_princess
		for i_kd in wishlist:
			if kds[i_kd - 1] == 0:
				kds[i_kd - 1] = 1
				check_free = -1
				break
		free_pr = max(free_pr, check_free)
	if free_pr == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(free_pr + 1, kds.index(0) + 1)


for _ in range(int(input())):
	k = int(input())
	l = []
	for t in range(k):
		m = list(map(int, input().split()))
		l.append(m[1:])
	d = {}
	mk = {}
	f = -1
	a = -1
	for t in range(k):
		for i in l[t]:
			if d.get(i, 0) == 0:
				d[i] = 1
				mk[t + 1] = 1
				break
	for t in range(1, k + 1):
		if d.get(t, 0) == 0:
			f = t
		if mk.get(t, 0) == 0:
			a = t
	if f == -1 and a == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(a, f)


t = int(input())
for k in range(t):
	n = int(input())
	res_daughter = 0
	kings = set()
	for i in range(n):
		gi = input().split()
		g = int(gi[0])
		isRes = True
		for j in range(1, g + 1):
			if gi[j] not in kings:
				kings.add(gi[j])
				isRes = False
				break
		if isRes and res_daughter == 0:
			res_daughter = i + 1
	if res_daughter > 0:
		for i in range(1, n + 1):
			if str(i) not in kings:
				print('IMPROVE')
				print(res_daughter, str(i))
				break
	else:
		print('OPTIMAL')


from sys import stdin, stdout
n = int(stdin.readline())
for _ in range(n):
	m = int(stdin.readline())
	h = {}
	unlucky = 0
	for p in range(1, m + 1):
		info = [int(x) for x in stdin.readline().split()][1:]
		min_ = float('inf')
		for i in info:
			if i < min_ and i not in h:
				min_ = i
		if min_ != float('inf'):
			h[min_] = p
		else:
			unlucky = p
	if unlucky == 0:
		print('OPTIMAL')
	else:
		for k in range(1, m + 1):
			if k not in h:
				print('IMPROVE')
				print(unlucky, k)
				break


from sys import stdin
inp = stdin.readline
t = int(inp())
for _ in range(t):
	n = int(inp())
	p = [False for i in range(n)]
	f = -1
	for j in range(n):
		d = list(map(lambda x: int(x) - 1, inp().split()))
		for i in d[1:]:
			if p[i] == False:
				p[i] = True
				break
		else:
			f = j
	if f == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(f + 1, p.index(False) + 1)


t = int(input())
for tt in range(t):
	n = int(input())
	p = []
	for i in range(n):
		p.append(list(map(int, input().split(' '))))
	a = []
	b = []
	for i in range(n):
		a.append(1)
		b.append(1)
	for i in range(n):
		if len(p[i]) == 2 and p[i][1] == 0:
			continue
		for j in range(1, len(p[i])):
			if b[p[i][j] - 1] == 1:
				b[p[i][j] - 1] = 0
				a[i] = 0
				break
	cont = False
	for i in range(n):
		if a[i] == 1:
			for j in range(n):
				if b[j] == 1:
					print('IMPROVE')
					print(i + 1, j + 1)
					cont = True
					break
			if cont:
				break
	if cont == False:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	s = [1] * n
	a = []
	for i in range(n):
		c = 0
		for j in list(map(int, input().split()))[1:]:
			if s[j - 1]:
				s[j - 1] = 0
				c = 1
				break
		if c == 0:
			a.append(i + 1)
	if len(a) > 0:
		print('IMPROVE')
		print(a[0], end=' ')
		for i in range(n):
			if s[i]:
				print(i + 1)
				break
	else:
		print('OPTIMAL')


t = int(input())
for x in range(t):
	n = int(input())
	val = [0] * n
	temp = []
	for j in range(n):
		arr = list(map(int, input().split()))
		if arr[0] == 0:
			temp.append(j + 1)
		else:
			flag = False
			for i in range(1, len(arr)):
				if val[arr[i] - 1] == 0:
					val[arr[i] - 1] = 1
					flag = True
					break
			if not flag:
				temp.append(j + 1)
	result = -1
	for i in range(n):
		if val[i] == 0:
			result = i + 1
			break
	if result == -1 and len(temp) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(temp[0], result)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from sys import stdout
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	alive = [True] * n
	for i in range(n):
		(k, *l) = map(int, input().split())
		for j in range(k):
			if alive[l[j] - 1]:
				alive[l[j] - 1] = False
				break
		else:
			notmat = i
	try:
		ans = alive.index(True) + 1
		print('IMPROVE\n')
		print(str(notmat + 1) + ' ' + str(ans) + '\n')
	except:
		print('OPTIMAL\n')


t = int(input())
for _ in range(t):
	n = int(input())
	v = []
	for _ in range(n):
		temp = list(map(int, input().split()))
		v.append(temp[1:])
	taken = {}
	firstMissed = -1
	for (i, l) in enumerate(v, 1):
		found = False
		for princess in l:
			if princess not in taken:
				taken[princess] = 0
				found = True
				break
		if not found and firstMissed == -1:
			firstMissed = i
	if firstMissed == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(firstMissed, [i for i in range(1, n + 1) if i not in taken][0])


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	wasg = [0] * (n + 1)
	wasb = [0] * (n + 1)
	wasg[0] = wasb[0] = 1
	ff = 0
	for i in range(n):
		for j in map(int, input().split()[1:]):
			if not wasb[j]:
				wasb[j] = wasg[i + 1] = 1
				ff += 1
				break
	if ff == n:
		print('OPTIMAL')
	else:
		print('IMPROVE', wasg.index(0), wasb.index(0))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	matrix = []
	visited = [0] * (n + 1)
	girl = [0] * (n + 1)
	for i in range(n):
		arr = [int(k) for k in stdin.readline().split()]
		matrix.append(arr[1:])
	for i in range(n):
		for j in range(len(matrix[i])):
			if visited[matrix[i][j]] == 0:
				visited[matrix[i][j]] = 1
				girl[i + 1] = 1
				break
	if visited.count(1) == n:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		for i in range(1, n + 1):
			if girl[i] == 0:
				stdout.write(str(i) + ' ')
				break
		for i in range(1, n + 1):
			if visited[i] == 0:
				stdout.write(str(i) + '\n')
				break


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	d1 = {}
	l = []
	d = {}
	for i in range(n):
		l.append(list(map(int, stdin.readline().split()))[1:])
	for i in range(n):
		j = 0
		if len(l[i]) != 0:
			x = l[i][j]
			while x in d:
				j += 1
				if j < len(l[i]):
					x = l[i][j]
				else:
					break
			d[x] = 1
			if j < len(l[i]):
				d1[i + 1] = 1
	if len(d) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if i + 1 not in d1:
				a = i + 1
				break
		for i in range(n):
			if i + 1 not in d:
				b = i + 1
				break
		print(a, b)


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

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

def fin():
	return int(stdin.readline().strip())

def fint():
	return list(map(int, stdin.readline().split()))

def main():
	n = fin()
	married_prince = [False] * n
	married_daughter = [False] * n
	for i in range(n):
		o = fint()
		for j in o[1:]:
			if married_prince[j - 1] == False:
				married_prince[j - 1] = True
				married_daughter[i] = True
				break
	for i in range(n):
		if married_daughter[i] == False:
			for j in range(n):
				if married_prince[j] == False:
					print('IMPROVE')
					print(i + 1, j + 1)
					return
	print('OPTIMAL')
t = fin()
for i in range(t):
	main()


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split()))[1:])
	avail = set([i for i in range(1, n + 1)])
	rem = []
	for j in range(n):
		x = l[j]
		for i in x:
			if i in avail:
				avail.remove(i)
				break
		else:
			rem.append(j)
	if len(avail) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(rem[0] + 1, list(avail)[0])


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append([int(j) for j in input().split()])
	prince = {}
	for i in range(1, n + 1):
		prince[i] = 1
	unmarried = []
	for i in range(n):
		flag = 0
		for j in range(1, l[i][0] + 1):
			if l[i][j] in prince:
				del prince[l[i][j]]
				flag = 1
				break
		if flag == 0:
			unmarried.append(i + 1)
	if len(unmarried) > 0:
		for i in prince:
			a = i
			break
		print('IMPROVE')
		print(unmarried[0], a)
	else:
		print('OPTIMAL')


from sys import stdin

def solve(n, k):
	d = set([i for i in range(1, n + 1)])
	h = True
	idx = -1
	for i in range(n):
		added = False
		for j in k[i]:
			if j in d:
				d.remove(j)
				added = True
				break
		if added == False and h:
			idx = i
			h = False
	if idx == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(idx + 1, d.pop())

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		n = int(inp())
		k = []
		for i in range(n):
			h = list(map(int, inp().split()))
			k.append(h[1:])
		solve(n, k)
main()


import os
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for tt in range(t):
	n = int(input())
	married = set()
	for i in range(n):
		kingdoms = list(map(int, input().split()))[1:]
		found = False
		for each in kingdoms:
			if each not in married:
				married.add(each)
				found = True
				break
		if not found:
			widow = i + 1
	if len(married) == n:
		print('OPTIMAL')
	else:
		i = 1
		while i in married:
			i += 1
		print('IMPROVE')
		print(widow, i)


t = int(input())
for test in range(t):
	n = int(input())
	f = [0 for i in range(n)]
	m = [0 for i in range(n)]
	mar = [[]] * n
	for i in range(n):
		mar[i] = [int(i) for i in input().split()][1:]
	for d in range(n):
		it = 0
		if len(mar[d]) > 0:
			while m[mar[d][it] - 1] == 1:
				it = it + 1
				if it == len(mar[d]):
					break
		if it < len(mar[d]):
			f[d] = 1
			m[mar[d][it] - 1] = 1
	if sum(f) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		a = 0
		b = 0
		for i in range(n):
			if f[i] == 0:
				a = i + 1
				break
		for i in range(n):
			if m[i] == 0:
				b = i + 1
				break
		print(a, b)


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	n = int(input())
	ls = [list(map(int, input().split())) for _ in range(n)]
	ms = [[] for _ in range(n)]
	for (i, l) in enumerate(ls):
		if len(l) > 1:
			for k in l[1:]:
				ms[k - 1].append(i)
	married_l = [False for _ in range(n)]
	married_r = [False for _ in range(n)]
	for (i, m) in enumerate(ms):
		if m:
			for p in m:
				if not married_l[p]:
					married_l[p] = True
					married_r[i] = True
					break
	(cur_l, cur_r) = (0, 0)
	while cur_l < n and married_l[cur_l]:
		cur_l += 1
	while cur_r < n and married_r[cur_r]:
		cur_r += 1
	if cur_l == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(cur_l + 1, cur_r + 1)


from sys import stdin, stdout
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007

def solve():
	n = inp()
	ind = -1
	l = [0]
	found = 0
	v = [False for i in range(n + 1)]
	for i in range(1, n + 1):
		x = li()
		f = 0
		a = x[0]
		for j in range(a):
			if not v[x[j + 1]]:
				v[x[j + 1]] = True
				f = 1
				break
		if not found and f == 0:
			ind = i
			found = 1
		l.append(x)
	if ind == -1:
		pr('OPTIMAL')
	else:
		a = l[ind]
		p = a[0]
		for i in range(1, n + 1):
			if not v[i]:
				print('IMPROVE')
				print(ind, i)
				break
for _ in range(inp()):
	solve()


import math
for t in range(int(input())):
	n = int(input())
	dic = {}
	for i in range(1, n + 1):
		dic[i] = False
	nt = []
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		flag = False
		for j in range(1, l[0] + 1):
			if dic[l[j]] == False:
				dic[l[j]] = True
				flag = True
				break
		if flag == False:
			nt.append(i)
	if len(nt) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if dic[i] == False:
				print(nt[0], i)
				break


for ___ in range(int(input())):
	n = int(input())
	dic = {}
	kingdom = set({})
	princess = set({})
	for i in range(n):
		kingdom.add(i + 1)
		princess.add(i + 1)
		li = list(map(int, input().split()))
		if li == 0:
			dic[i] = {0}
		else:
			dic[i] = list(li[1:])
	for j in range(n):
		for k in dic[j]:
			if k in kingdom:
				kingdom.remove(k)
				princess.remove(j + 1)
				break
	if len(princess) == 0:
		print('OPTIMAL')
	else:
		for j in kingdom:
			break
		for k in princess:
			break
		print('IMPROVE')
		print(k, j)


for _ in range(int(input())):
	n = int(input())
	king = [False] * n
	daughter = [False] * n
	for i in range(n):
		lis = list(map(int, input().split()))
		k = lis[1:]
		for j in k:
			if king[j - 1] == False:
				king[j - 1] = True
				daughter[i] = True
				break
	(newD, newK, countD, countK) = (list(), list(), 0, 0)
	for i in range(n):
		if daughter[i] == False:
			newD.append(i + 1)
			countD += 1
		if king[i] == False:
			newK.append(i + 1)
			countK += 1
	if countD > 0 and countK > 0:
		print('IMPROVE')
		print(newD[0], newK[0])
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	b = 0
	c = [0 for i in range(n + 1)]
	flag_1 = 1
	for i in range(n):
		k = list(map(int, input().split()))
		flag = 1
		for j in range(k[0]):
			if c[k[j + 1]] == 0:
				c[k[j + 1]] = 1
				flag = 0
				break
		if flag == 1:
			b = i + 1
	if b != 0:
		print('IMPROVE')
		for i in range(1, n + 1):
			if c[i] == 0:
				print(b, i)
				break
	else:
		print('OPTIMAL')


import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))

def main():
	for _ in range(nmbr()):
		n = nmbr()
		l = defaultdict(list)
		for i in range(n):
			a = lst()
			l[i + 1] += a[1:]
		kingdom_left = set([i for i in range(1, n + 1)])
		princess_left = set([i for i in range(1, n + 1)])
		for i in range(1, n + 1):
			for v in l[i]:
				if v in kingdom_left:
					kingdom_left.remove(v)
					princess_left.remove(i)
					break
		if kingdom_left and princess_left:
			print('IMPROVE')
			print(list(princess_left)[0], list(kingdom_left)[0])
		else:
			print('OPTIMAL')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(1):
	main()


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	T = Scanner.int()
	for _ in range(T):
		N = Scanner.int()
		M = {}
		G = {}
		for i in range(N):
			M[i] = True
			G[i] = False
		for i in range(N):
			(_, *A) = Scanner.map_int()
			for a in A:
				if M[a - 1]:
					M[a - 1] = False
					G[i] = True
					break
		if False in G.values():
			print('IMPROVE')
			for i in range(N):
				if not G[i]:
					break
			for j in range(N):
				if M[j]:
					break
			print(i + 1, j + 1)
		else:
			print('OPTIMAL')
main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	man = [x for x in range(1, n + 1)]
	man = set(man)
	can = False
	(a, b) = (0, 0)
	for i in range(n):
		t = list(R())
		so = False
		for j in range(1, t[0] + 1):
			if t[j] in man:
				man.remove(t[j])
				so = True
				break
		if not so:
			can = True
			a = i + 1
	if can:
		b = list(man)[0]
		print('IMPROVE')
		print(a, b)
	else:
		print('OPTIMAL')


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
for _ in range(I()):
	n = I()
	a = [0] * n
	for i in range(n):
		a[i] = L()
	merry = [0] * n
	cnt = 0
	sol = 0
	sol2 = 0
	for i in range(n):
		fl = True
		for j in range(1, len(a[i])):
			if merry[a[i][j] - 1] == 0:
				merry[a[i][j] - 1] = 1
				cnt += 1
				fl = False
				break
		if fl:
			sol = i + 1
	for i in range(n):
		if merry[i] == 0:
			sol2 = i + 1
	if sol > 0:
		print('IMPROVE\n' + str(sol) + ' ' + str(sol2))
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	s = list()
	king = list()
	z = 1
	b = list()
	for i in range(1, n + 1):
		a = list(map(int, input().split()))
		a.pop(0)
		b.append(a[:])
		king.append(0)
		s.append(0)
	for k in range(len(b)):
		for m in range(len(b[k])):
			if king[b[k][m] - 1] != 1:
				king[b[k][m] - 1] = 1
				s[k] = 1
				break
			else:
				continue
	if 0 in king or 0 in s:
		print('IMPROVE')
		x = s.index(0)
		y = king.index(0)
		x = x + 1
		y = y + 1
		print(x, y)
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split()))[1:])
	s = set()
	for i in range(n):
		t = n + 1
		for x in a[i]:
			if x not in s:
				t = x
				break
		if t != n + 1:
			s.add(t)
		else:
			res = i + 1
	if len(s) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in s:
				print(res, i)
				break


for _ in range(int(input())):
	n = int(input())
	arr = [0 for i in range(n + 1)]
	s = []
	for i in range(n):
		x = [*map(int, input().split())]
		val = x[0]
		del x[0]
		x.sort()
		flag = False
		for j in range(val):
			if arr[x[j]] == 0:
				arr[x[j]] = 1
				flag = True
				break
		if not flag and len(s) == 0:
			s.append(i + 1)
	flag = True
	for i in range(1, n + 1):
		if arr[i] == 0:
			flag = False
			break
	if flag:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(s[0], end=' ')
		for i in range(1, n + 1):
			if arr[i] == 0:
				print(i)
				break


from sys import stdin
input = stdin.readline

def getAns(n, p):
	visited = [False] * (n + 1)
	index = -1
	for i in range(n):
		j = 1
		while j < p[i][0] + 1 and visited[p[i][j]]:
			j += 1
		if j == p[i][0] + 1:
			index = i
		elif p[i][0] > 0:
			visited[p[i][j]] = True
	if index < 0:
		print('OPTIMAL')
		return
	else:
		for k in range(1, n + 1):
			if not visited[k]:
				print('IMPROVE')
				print(*[index + 1, k])
				return
t = int(input())
for _ in range(t):
	n = int(input())
	p = [[] for i in range(n)]
	for i in range(n):
		g = list(map(int, input().split()))
		p[i] = g
	getAns(n, p)


for _ in range(int(input())):
	n = int(input())
	f = 0
	g = 0
	ls = []
	lf = [0] * n
	for ddd in range(n):
		l = list(map(int, input().split()))
		for i in range(1, l[0] + 1):
			if lf[l[i] - 1] == 0:
				ls.append(l[i])
				f = 1
				lf[l[i] - 1] = 1
				break
		if f == 0 and g == 0:
			g = 1
			y = ddd
		f = 0
	if len(ls) == 0:
		ans = 1
	else:
		ls.sort()
		if ls[0] != 1:
			ans = 1
		else:
			h = 0
			for i in range(1, len(ls)):
				if ls[i] != ls[i - 1] + 1:
					h = 1
					ans = ls[i - 1] + 1
			if h == 0:
				ans = ls[-1] + 1
	if g == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(y + 1, ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
from collections import defaultdict
from heapq import heappop, heappush, heapify
t = int(input())
for _ in range(t):
	hash = defaultdict(list)
	n = int(input())
	hash1 = defaultdict(set)
	for i in range(1, n + 1):
		hash[i] = list(map(int, input().split()))[1:]
		hash1[i] = set(hash[i])
	ma = defaultdict(bool)
	pos = []
	for i in range(1, n + 1):
		flag = 0
		for j in hash[i]:
			if ma[j] == False:
				ma[j] = True
				flag = 1
				break
		if not flag:
			pos.append(i)
	ka = set()
	for i in range(1, n + 1):
		if ma[i] == False:
			ka.add(i)
	(ans1, ans2) = (-1, -1)
	for i in pos:
		s = ka - hash1[i]
		if s != set():
			ans1 = i
			ans2 = s.pop()
			break
	if ans1 != -1:
		print('IMPROVE')
		print(ans1, ans2)
	else:
		print('OPTIMAL')


T = int(input())
for _ in range(0, T):
	n = int(input())
	L = []
	kk = [0] * (n + 1)
	dd = [0] * (n + 1)
	c = 0
	for i in range(n):
		s = [int(x) for x in input().split()]
		for j in range(1, len(s)):
			if kk[s[j]] == 0:
				kk[s[j]] = 1
				dd[i + 1] = 1
				c += 1
				break
	if c == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		e1 = 0
		e2 = 0
		for i in range(1, n + 1):
			if dd[i] == 0:
				e1 = i
				break
		for i in range(1, n + 1):
			if kk[i] == 0:
				e2 = i
				break
		print(e1, e2)


import sys
import heapq

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

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

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

def main():
	n = iinput()
	q = [[] for i in range(n)]
	f = [False for i in range(n)]
	for i in range(n):
		w = rlinput()
		for o in w[1:]:
			q[i].append(o - 1)
	t = []
	e = []
	for i in range(n):
		fl = False
		for o in range(len(q[i])):
			if not f[q[i][o]]:
				f[q[i][o]] = True
				fl = True
				break
		if not fl:
			t.append(i)
	for i in range(n):
		if not f[i]:
			e.append(i)
	if not len(t):
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(t[0] + 1, e[0] + 1)
for i in range(iinput()):
	main()


for _ in range(int(input())):
	n = int(input())
	prince = [False for _ in range(n)]
	notf = None
	for i in range(1, n + 1):
		dlst = [int(x) for x in input().split()[1:]]
		for val in dlst:
			if val > 0 and (not prince[val - 1]):
				prince[val - 1] = True
				break
		else:
			if notf is None:
				notf = i
	if all(prince):
		ans = 'OPTIMAL'
	else:
		ans = 'IMPROVE\n'
		ans += str(notf) + ' ' + str(prince.index(False) + 1)
	print(ans)


for _ in range(int(input())):
	m = int(input())
	king = [0] * (m + 1)
	(count, z) = (0, list())
	for j in range(m):
		flag = 0
		lst = [int(i) for i in input().split()]
		for k in range(1, lst[0] + 1):
			if king[lst[k]] == 0:
				(flag, king[lst[k]]) = (1, 1)
				count += 1
				break
		if flag == 0:
			z.append(j)
	if count != m:
		print('IMPROVE')
		for op in range(1, m + 1):
			if king[op] == 0:
				print(z[0] + 1, op)
				break
	else:
		print('OPTIMAL')


import math
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
for i in range(n):
	x = I()
	d = {}
	b = []
	y = x
	for i in range(1, x + 1):
		a = L()
		a = a[1:]
		f = 0
		for j in a:
			if j not in d:
				d[j] = 0
				y -= 1
				f = 1
				break
		if f == 0:
			b.append(i)
	if y == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for k in range(1, x + 1):
			if k not in d:
				print(b[0], k)
				break


import math
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	d = defaultdict(int)
	used = [False] * n
	noUsed = []
	q = 0
	for i in range(n):
		a = [int(i) for i in input().split()]
		b = a[1:]
		f = 0
		for j in b:
			if used[j - 1] == False:
				used[j - 1] = True
				f = 1
				break
		if f == 0:
			noUsed.append(i + 1)
	if len(noUsed) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(noUsed[0], used.index(False) + 1)


t = int(input())
for j in range(t):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	girls = []
	boys = []
	for i in range(n):
		girls.append(0)
		boys.append(0)
	for i in range(n):
		ch = 1
		while girls[i] == 0 and ch < len(a[i]):
			if boys[a[i][ch] - 1] == 0:
				girls[i] = a[i][ch]
				boys[a[i][ch] - 1] = i + 1
			ch += 1
	imp = False
	tx = ''
	for i in range(n):
		if girls[i] == 0 and (not imp):
			for g in range(n):
				if boys[g] == 0:
					imp = True
					tx = str(i + 1) + ' ' + str(g + 1)
	if imp:
		print('IMPROVE')
		print(tx)
	else:
		print('OPTIMAL')


from sys import stdin
t = int(stdin.readline())
while t:
	t -= 1
	n = int(stdin.readline())
	king = [0] * n
	q = -1
	for i in range(n):
		l = list(map(int, stdin.readline().split()))[1:]
		for j in l:
			if king[j - 1] == 0:
				king[j - 1] = 1
				break
		else:
			q = i
	if q == -1:
		print('OPTIMAL')
	else:
		k = king.index(0)
		print('IMPROVE')
		print(q + 1, k + 1)


from bisect import bisect_left

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1
from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	m = [0] * (n + 1)
	want = {}
	dum = []
	for i in range(n):
		want[i + 1] = [int(j) for j in input().split()][1:]
		f = 0
		for j in want[i + 1]:
			if m[j] == 0:
				m[j] = 1
				f = 1
				break
		if f == 0:
			dum += [i + 1]
	kum = []
	for i in range(1, n + 1):
		if m[i] == 0:
			kum += [i]
	if kum == []:
		print('OPTIMAL')
	else:
		f = 0
		for i in kum:
			for j in dum:
				if bs(want[j], i) == -1:
					f = 1
					print('IMPROVE')
					print(j, i)
					break
			if f == 1:
				break
		if f == 0:
			print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	dic = {}
	flag = 0
	for i in range(n):
		if i + 1 not in dic:
			dic[i + 1] = 1
	for i in range(n):
		l = list(map(int, input().split()))
		imp = 0
		if l[0] != 0:
			for j in range(l[0]):
				if l[j + 1] in dic:
					del dic[l[j + 1]]
					break
				else:
					pass
				if j == l[0] - 1 and flag == 0:
					prncs = i + 1
					flag = 1
		elif flag == 0:
			prncs = i + 1
			flag = 1
	lst = list(dic.keys())
	if flag == 1 and len(lst) >= 1:
		print('IMPROVE')
		print(prncs, lst[0])
	else:
		print('OPTIMAL')


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(n, di):
	taken = [False] * (n + 1)
	unmarried = None
	for (d, choices) in di.items():
		if len(choices) == 0:
			unmarried = d
			continue
		(min_choice, found) = (min(choices), True)
		if taken[min_choice]:
			yes = False
			for c in choices:
				if not taken[c]:
					taken[c] = True
					yes = True
					break
			if yes:
				continue
			found = False
		if not found:
			unmarried = d
			continue
		taken[min_choice] = True
	if all(taken[1:]):
		write('OPTIMAL')
		return
	if not any(taken):
		write('IMPROVE')
		write(1, 1)
		return
	write('IMPROVE')
	write(unmarried, next((i for i in range(1, n + 1) if not taken[i])))

def main():
	for _ in range(r_int()):
		n = r_int()
		di = defaultdict(list)
		for i in range(1, n + 1):
			di[i] = r_array()[1:]
		solution(n, di)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(stdin.readline())
	p = set(range(1, n + 1))
	u = []
	m = []
	for i in range(n):
		a = list(map(int, stdin.readline().split()))
		a = a[1:]
		d = p.intersection(a)
		if len(d) == 0:
			u.append(a)
			m.append(i + 1)
		else:
			p.remove(list(d)[0])
	okay = 0
	for i in range(len(u)):
		if okay:
			break
		s = p.difference(u[i])
		if len(s) != 0:
			for j in s:
				print('IMPROVE')
				print(m[i], j)
				okay = 1
				break
	if not okay:
		print('OPTIMAL')


ileP = int(input())
for i in range(ileP):
	ileK = int(input())
	oni = [False] * (ileK + 1)
	one = [False] * (ileK + 1)
	oni[0] = True
	one[0] = True
	for j in range(1, ileK + 1):
		tmp = list(map(int, input().split()))
		for k in tmp[1:]:
			if not oni[k]:
				oni[k] = True
				one[j] = True
				break
	if False in one:
		print('IMPROVE')
		print(one.index(False), oni.index(False))
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	daughter = list(range(1, n + 1))
	kingdom = set(range(1, n + 1))
	remaining_daughter = []
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		k = set(l[1:])
		if len(k) > 0:
			t = k.intersection(kingdom)
			if len(t) == 0:
				remaining_daughter.append(i)
			else:
				kingdom.remove(min(t))
		else:
			remaining_daughter.append(i)
	if len(remaining_daughter) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(remaining_daughter[0], kingdom.pop())


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	K = []
	for n in range(N):
		K.append(getInts()[1:])
		K[n].sort()
	unused = set([j + 1 for j in range(N)])
	curr = 0
	for n in range(N):
		flag = False
		for k in K[n]:
			if k in unused:
				unused.remove(k)
				flag = True
				break
		if not flag:
			curr = n + 1
	if curr:
		print('IMPROVE')
		x = next(iter(unused))
		print(curr, x)
		return
	print('OPTIMAL')
	return
for _ in range(getInt()):
	solve()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	pref = defaultdict(list)
	daughters = [-1] * (n + 1)
	kingdoms = [-1] * (n + 1)
	for daug in range(1, n + 1):
		daug_pref = list(map(int, input().strip().split()))
		for i in range(1, daug_pref[0] + 1):
			pref[daug].append(daug_pref[i])
			if daughters[daug] == -1 and kingdoms[daug_pref[i]] == -1:
				daughters[daug] = daug_pref[i]
				kingdoms[daug_pref[i]] = daug
	optimal = 1
	for daug in range(1, n + 1):
		if daughters[daug] == -1 and optimal:
			for king in range(1, n + 1):
				if kingdoms[king] == -1:
					print('IMPROVE')
					print(daug, king)
					optimal = 0
					break
	if optimal:
		print('OPTIMAL')


import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input

def main(t=1):
	for i in range(t):
		n = int(input())
		used = set()
		unused = set([i + 1 for i in range(n)])
		ans = -1
		for i in range(n):
			c = list(map(int, input().split()))
			k = c[0]
			f = True
			for j in range(k):
				j += 1
				if c[j] not in used:
					used.add(c[j])
					unused.remove(c[j])
					f = False
					break
			if f:
				ans = i + 1
		if ans == -1:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(ans, unused.pop())
main(int(input()))


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	ans = []
	for i in range(n):
		a.append(list(map(int, input().split())))
		b.append(i + 1)
	for i in range(n):
		t = 0
		for j in range(a[i][0]):
			if b[a[i][j + 1] - 1] == a[i][j + 1]:
				b[a[i][j + 1] - 1] = 0
				t = 1
				break
			else:
				continue
		if t == 0:
			ans.append(i + 1)
	for i in range(n):
		if b[i] != 0:
			ans.append(i + 1)
			break
		else:
			continue
	if len(ans) != 0:
		print('IMPROVE')
		print(ans[0], ans[-1])
	else:
		print('OPTIMAL')


import math

def main():
	T = int(input())
	for t in range(T):
		n = int(input())
		prince = [1 for i in range(n)]
		princess = [1 for i in range(n)]
		dList = [list(map(int, input().split()[1:])) for i in range(n)]
		for i in range(n):
			for j in range(len(dList[i])):
				if prince[dList[i][j] - 1] == 1:
					prince[dList[i][j] - 1] = 0
					princess[i] = 0
					break
		optimized = True
		princeIndex = -1
		princessIndex = -1
		for i in range(n):
			if princeIndex == -1 and prince[i] == 1:
				optimized = False
				princeIndex = i + 1
			if princessIndex == -1 and princess[i] == 1:
				optimized = False
				princessIndex = i + 1
		if not optimized:
			print('IMPROVE')
			print(princessIndex, princeIndex)
		else:
			print('OPTIMAL')
main()


for _ in range(int(input())):
	n = int(input())
	a = [0] * (n + 1)
	d = [0] * (n + 1)
	flag = 0
	f = 0
	for i in range(n):
		l = list(map(int, input().split()))
		l.pop(0)
		j = 0
		while j < len(l):
			if a[l[j]] == 0 and l[j] != 0:
				a[l[j]] = 1
				d[i + 1] = 1
				break
			j += 1
	for i in range(1, n + 1):
		if a[i] == 0:
			x = i
			flag = 1
			break
	for i in range(1, n + 1):
		if d[i] == 0 and flag == 1:
			f = 1
			y = i
			break
	if f == 1:
		print('IMPROVE')
		print(y, x)
	else:
		print('OPTIMAL')


import collections
t = int(input())

def solve(n, d):
	da = set([i for i in range(1, n + 1)])
	kd = set([i for i in range(1, n + 1)])
	for i in range(1, n + 1):
		while d[i] and d[i][-1] not in kd:
			d[i].pop()
		if d[i]:
			kd.remove(d[i].pop())
			da.remove(i)
	if not da:
		return 'OPTIMAL'
	else:
		pick_da = list(da)[-1]
		pick_kd = list(kd)[-1]
		return str(pick_da) + ' ' + str(pick_kd)
for _ in range(t):
	n = int(input())
	d = collections.defaultdict(list)
	for i in range(n):
		arr = list(map(int, input().split()))
		d[i + 1] = sorted(arr[1:], reverse=True)
	ans = solve(n, d)
	if ans == 'OPTIMAL':
		print(ans)
	else:
		print('IMPROVE')
		print(ans)


import io
import os
from sys import stdin, stdout
input = stdin.readline
for t in range(int(input())):
	n = int(input())
	c = set()
	flag = -1
	for i in range(n):
		b = list(map(int, input().split()))
		d = -1
		for j in range(1, b[0] + 1):
			if b[j] not in c:
				c.add(b[j])
				d = j
				break
		if d == -1 and flag == -1:
			flag = i
	if flag == -1:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		print(flag + 1, end=' ')
		for j in range(1, n + 1):
			if j not in c:
				print(j)
				break


for _ in range(int(input())):
	n = int(input())
	k = [list(map(int, input().split())) for i in range(n)]
	for i in range(len(k)):
		k[i] = k[i][1:]
	c1 = [0] * (n + 1)
	f = [0] * (n + 1)
	co = 1
	k2 = 1
	for k1 in k:
		fl = 0
		for j in k1:
			if f[j] == 0:
				fl = 1
				break
		if fl:
			f[j] = 1
			c1[co] = 1
		else:
			k2 = co
		co += 1
	f2 = 1
	for i in range(1, n + 1):
		if f[i] == 0:
			f2 = 0
			print('IMPROVE')
			print(k2, i)
			break
		if f2 == 0:
			break
	if f2:
		print('OPTIMAL')


def areallzero(arr):
	for i in range(len(arr)):
		if arr[i]:
			return i
	return -1
t = int(input())
for you in range(t):
	n = int(input())
	arrofprince = [1 for i in range(n)]
	listofpref = []
	arrofprincess = [1 for i in range(n)]
	for ui in range(n):
		l = input().split()
		li = [int(i) for i in l]
		li.pop(0)
		listofpref.append(li)
	for i in range(n):
		for x in listofpref[i]:
			if arrofprince[x - 1]:
				arrofprince[x - 1] = 0
				arrofprincess[i] = 0
				break
	j = areallzero(arrofprince)
	if j == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if arrofprincess[i]:
				print(i + 1, j + 1)
				break


for _ in range(int(input())):
	n = int(input())
	li = [True] * n
	li_p = []
	for i in range(n):
		a = list(map(int, input().split()))
		a = a[1:]
		a.sort()
		f = True
		for j in a:
			if li[j - 1]:
				li[j - 1] = False
				f = False
				break
		if f:
			li_p.append(i + 1)
	if len(li_p) != 0:
		print('IMPROVE')
		print(li_p[0], li.index(True) + 1)
	else:
		print('OPTIMAL')


out = ''
for _ in range(int(input())):
	a = []
	n = int(input())
	prince = [False] * n
	princess = 0
	for _ in range(n):
		a.append(list(map(int, input().split()))[1:])
	for (a, i) in zip(a, range(1, n + 1)):
		for a in a:
			if prince[a - 1] == 0:
				prince[a - 1] = True
				break
		else:
			princess = i
	try:
		out += f'IMPROVE\n{princess} {prince.index(False) + 1}\n'
	except ValueError:
		out += 'OPTIMAL\n'
print(out)


t = int(input())
for i in range(t):
	n = int(input())
	prince = [0] * n
	net = []
	for j in range(n):
		a = list(map(int, input().split()))
		k = a.pop(0)
		boo = False
		for z in a:
			if prince[z - 1] == 0:
				prince[z - 1] = 1
				boo = True
				break
		if boo == False:
			net.append(j + 1)
	if net == []:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(net[0], prince.index(0) + 1)


for i in range(int(input())):
	n = int(input())
	prince = [0] * n
	arr = []
	for j in range(n):
		a = list(map(int, input().split()))
		k = a.pop(0)
		flag = False
		for i in a:
			if prince[i - 1] == 0:
				prince[i - 1] = 1
				flag = True
				break
		if flag == False:
			arr.append(j + 1)
	if len(arr) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(arr[0], prince.index(0) + 1)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		chosen = list(range(1, n + 1))
		dic = {}
		for i in chosen:
			dic[i] = False
		count = 0
		queenwithnohusand = None
		lstrino = []
		for i in range(n):
			lst = list(map(int, input().split()))
			lstrino.append(lst)
		for i in range(n):
			lst = lstrino[i]
			princesschoice = lst[1:]
			found = False
			for ele in princesschoice:
				if not dic[ele]:
					dic[ele] = True
					count += 1
					found = True
					break
			if not found and (not queenwithnohusand):
				queenwithnohusand = i + 1
		for ele in dic:
			if not dic[ele]:
				husbandcouldbe = ele
				break
		if count == n:
			yield 'OPTIMAL'
		else:
			yield 'IMPROVE'
			yield (str(queenwithnohusand) + ' ' + str(husbandcouldbe))
t = int(input())
ans = gift()
print(*ans, sep='\n')


from sys import stdin, stdout
t = int(input())
for p in range(0, t):
	n = int(stdin.readline())
	v = [0]
	for i in range(0, n):
		a = stdin.readline().split()
		for j in range(0, len(a)):
			a[j] = int(a[j])
		if a[0] == 0:
			v.append([])
		else:
			v.append(a[1:])
	visited = [0] * (n + 1)
	married = [0] * (n + 1)
	for i in range(1, n + 1):
		for j in v[i]:
			if visited[j] == 0:
				visited[j] = 1
				married[i] = 1
				break
	if visited.count(1) == n:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		stdout.write(str(married[1:].index(0) + 1) + ' ' + str(visited[1:].index(0) + 1))
		stdout.write('\n')


for t in range(int(input())):
	A = list()
	n = int(input())
	reserved = set()
	free = -1
	for i in range(n):
		A = list(map(int, input().split()))
		A = A[1:]
		for it in A:
			if it not in reserved:
				reserved.add(it)
				break
		else:
			free = i
	if free == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if i not in reserved:
				print('IMPROVE')
				print(free + 1, i)
				break


t = int(input())
ans = []
for i in range(t):
	d = set()
	q = []
	n = int(input())
	for j in range(n):
		a = list(map(int, input().split()))
		a.pop(0)
		a.sort()
		for g in a:
			if not g in d:
				q += [g]
				d.add(g)
				break
		else:
			q += [0]
	if len(d) == n:
		ans.append(['OPTIMAL'])
	else:
		r = set((z for z in range(1, n + 1)))
		for j in range(n):
			if q[j] == 0:
				ans.append(['IMPROVE', j + 1, min(r - d)])
				break
for i in range(t):
	print(ans[i][0])
	if ans[i][0] == 'IMPROVE':
		print(ans[i][1], ans[i][2])


t = int(input())
for _ in range(t):
	n = int(input())
	prince = {}
	pairs = {}
	for i in range(n):
		prince[i + 1] = -1
		pairs[i] = -1
	pransd = False
	for i in range(n):
		inpl = list(map(int, input().split()))
		nl = inpl[1:]
		if len(nl) == 0:
			continue
		else:
			j = 0
			while prince[nl[j]] == 1:
				j = j + 1
				if j == len(nl):
					break
			if j != len(nl):
				prince[nl[j]] = 1
				pairs[i] = nl[j]
	if pransd == False:
		for i in range(n):
			if pransd == True:
				break
			if pairs[i] == -1:
				for j in range(n):
					if prince[j + 1] == -1:
						print('IMPROVE')
						print(i + 1, j + 1)
						pransd = True
						break
	if pransd == False:
		print('OPTIMAL')


T = int(input())
for t in range(T):
	n = int(input())
	kingdom = [True] + [False for i in range(1, n + 1)]
	princess_found = False
	for i in range(n):
		A = [int(r) for r in input().split()]
		for j in range(1, A[0] + 1):
			if not kingdom[A[j]]:
				kingdom[A[j]] = True
				break
		else:
			if not princess_found:
				princess_found = True
				princess_index = i + 1
	if princess_found:
		print('IMPROVE')
		for i in range(n + 1):
			if not kingdom[i]:
				target = i
				print(princess_index, target)
				break
	else:
		print('OPTIMAL')


from sys import stdin
input = stdin.buffer.readline
t = int(input())
for i in range(t):
	n = int(input())
	c = -1
	q = [0 for i in range(n + 1)]
	for y in range(n):
		m = list(map(int, input().split()))
		f = 0
		for j in range(1, len(m)):
			if q[m[j]] == 0:
				f = 1
				q[m[j]] = 1
				break
		if f == 0:
			c = y + 1
	if c == -1:
		print('OPTIMAL')
	else:
		for j in range(1, n + 1):
			if q[j] == 0:
				print('IMPROVE')
				print(c, j)
				break


import sys
input = sys.stdin.readline
t = int(input())
for j in range(t):
	n = int(input())
	princes = {}
	sadPrincess = []
	for go in range(n):
		princes[go + 1] = 1
	for go in range(n):
		princess = list(map(int, input().split(' ')))
		done = False
		for l in range(1, len(princess)):
			if princes[princess[l]] == 1:
				princes[princess[l]] = 0
				done = True
				break
		if done == False:
			sadPrincess.append(go + 1)
	if len(sadPrincess) > 0:
		print('IMPROVE')
		for f in princes:
			if princes[f] == 1:
				print(str(sadPrincess[0]) + ' ' + str(f))
				break
	else:
		print('OPTIMAL')


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	n = get_int()
	modify = False
	(d, p) = (0, 0)
	dau = [True] * n
	pref_lst = {}
	for i in range(n):
		pref_lst[i] = get_int_list()[1:]
	prince = [True] * n
	while True:
		modify = False
		for dau_no in range(n):
			if dau[dau_no] == True:
				for j in pref_lst[dau_no]:
					if prince[j - 1] == True:
						prince[j - 1] = False
						dau[dau_no] = False
						match = True
						modify = True
						break
			else:
				continue
		if not modify:
			break
	if True in dau and True in prince:
		d = dau.index(True) + 1
		p = prince.index(True) + 1
		print('IMPROVE')
		print(d, p)
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for i in range(n):
		l = list(map(int, input().split()))
		a.append(l[1:])
	visited = [0] * (n + 1)
	girl = [0] * (n + 1)
	for i in range(len(a)):
		for j in range(len(a[i])):
			if visited[a[i][j]] == 0:
				visited[a[i][j]] = 1
				girl[i] = 1
				break
	visited.pop(0)
	if visited.count(1) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(len(girl)):
			if girl[i] == 0:
				print(i + 1, end=' ')
				break
		for i in range(len(visited)):
			if visited[i] == 0:
				print(i + 1)
				break


from sys import stdin, stdout
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	princess = [False] * n
	prince = [False] * n
	for j in range(n):
		ls = [int(x) for x in stdin.readline().split()]
		del ls[0]
		for k in ls:
			if not prince[k - 1]:
				prince[k - 1] = True
				princess[j] = True
				break
	op_princess = 0
	op_prince = 0
	for i in range(len(princess)):
		if not princess[i]:
			op_princess = i + 1
	for i in range(len(prince)):
		if not prince[i]:
			op_prince = i + 1
	if op_prince and op_princess:
		stdout.write('IMPROVE\n')
		stdout.write(str(op_princess) + ' ' + str(op_prince) + '\n')
	else:
		stdout.write('OPTIMAL\n')


def calc(optionsList):
	unusedDaughter = None
	usedKingdoms = [False] * (len(optionsList) + 5)
	for (daughterIdx, options) in enumerate(optionsList):
		kingdomFound = False
		for option in options:
			if not usedKingdoms[option]:
				usedKingdoms[option] = True
				kingdomFound = True
				break
		if not kingdomFound:
			unusedDaughter = daughterIdx
	toImprove = None
	if unusedDaughter is not None:
		for idx in range(1, len(optionsList) + 1):
			if not usedKingdoms[idx] and idx not in optionsList[unusedDaughter]:
				toImprove = '{} {}'.format(unusedDaughter + 1, idx)
				break
	if toImprove:
		print('IMPROVE')
		print(toImprove)
	else:
		print('OPTIMAL')
num_test_cases = int(input())
for _ in range(num_test_cases):
	num_kingdoms = int(input())
	optionsList = []
	for _ in range(num_kingdoms):
		options = [int(i) for i in input().split(' ')]
		options.pop(0)
		optionsList.append(options)
	calc(optionsList)


for _ in range(int(input())):
	myDic = {}
	princesses = int(input())
	for (x, y) in enumerate([1] * princesses):
		myDic.update({x + 1: y})
	leftOvers = []
	for x in range(princesses):
		choice = list(map(int, input().split()))
		if not choice[0]:
			leftOvers.append(x + 1)
		else:
			found = 0
			for k in choice[1:]:
				if k in myDic:
					del myDic[k]
					found += 1
					break
			if not found:
				leftOvers.append(x + 1)
	if leftOvers:
		print('IMPROVE')
		print(leftOvers[0], min(myDic.items())[0])
	else:
		print('OPTIMAL')


I = input
for _ in [0] * int(I()):
	r = range(int(I()))
	s = {*r}
	k = 0
	for i in r:
		j = next((j for j in map(int, I().split()[1:]) if {j - 1} & s), 0)
		s -= {j - 1}
		k = (i + 1, k)[j > 0]
	if k and s:
		print('IMPROVE', k, s.pop() + 1)
	else:
		print('OPTIMAL')


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(itg()):
	n = itg()
	st = set(range(1, n + 1))
	count = 0
	daughter = -1
	for i in range(n):
		prince = list(mpint())[1:]
		for p in prince:
			if p in st:
				st.remove(p)
				count += 1
				break
		else:
			daughter = i
	if daughter != -1:
		print('IMPROVE')
		print(daughter + 1, st.pop())
	else:
		print('OPTIMAL')


from sys import stdin

def func():
	return
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = []
	for i in range(n):
		ans = list(map(int, stdin.readline().split()))
		arr.append(ans[1:])
	cond = True
	val = 1
	final = [-1] * (n + 1)
	for i in range(n):
		if len(arr[i]) == 0:
			cond = False
			a = i + 1
		else:
			f = 1
			for j in range(len(arr[i])):
				if final[arr[i][j]] == -1:
					f = 0
					final[arr[i][j]] = 1
					break
			if f == 1:
				cond = False
				a = i + 1
	if cond == False:
		print('IMPROVE')
		for i in range(1, n + 1):
			if final[i] == -1:
				b = i
				break
		print(a, b)
	else:
		print('OPTIMAL')


import sys
if True:
	input = sys.stdin.readline
	t = int(input())
	for ii in range(t):
		n = int(input())
		a = [-1] * n
		b = [-1] * n
		for i in range(n):
			l = list(map(int, input().split()))
			if len(l) == 1:
				continue
			l = l[1:]
			for j in l:
				if b[j - 1] == -1:
					a[i] = j
					b[j - 1] = 1
					break
		if min(a) >= 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(a.index(-1) + 1, b.index(-1) + 1)


for _ in range(int(input())):
	n = int(input())
	d = {}
	fd = {}
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		l.pop(0)
		d[i] = l
		fd[i] = 0
	i = 0
	s = []
	for i in range(1, n + 1):
		r = d[i]
		f = 1
		while len(r) != 0 and f == 1:
			x = r.pop(0)
			if fd[x] == 0:
				fd[x] = 1
				f = 0
		if f == 1:
			s.append(i)
	g = 0
	for i in fd:
		if len(s) == 0:
			break
		elif fd[i] == 0:
			x = s.pop(0)
			print('IMPROVE')
			print(x, i)
			g = 1
			break
	if g == 0:
		print('OPTIMAL')


from collections import defaultdict

class Graph:

	def __init__(self, n):
		self.graph = defaultdict(list)
		self.Visited = [False] * (n + 1)
		self.Queen = [False] * (n + 1)
		self.N = N

	def addEdge(self, fr, to):
		self.graph[fr] = to

	def solve(self):
		for i in range(1, self.N + 1):
			for j in self.graph[i]:
				if self.Visited[j] == False:
					self.Visited[j] = True
					self.Queen[i] = True
					break
		King = -1
		Queen = -1
		for i in range(1, self.N + 1):
			if self.Visited[i] == False:
				King = i
				break
		for j in range(1, self.N + 1):
			if self.Queen[j] == False:
				Queen = j
				break
		if King == Queen == -1:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(Queen, King)

	def show(self):
		print(self.graph)
for _ in range(int(input())):
	N = int(input())
	G = Graph(N)
	for i in range(N):
		temp = [int(x) for x in input().split()]
		G.addEdge(i + 1, temp[1:])
	G.solve()


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	prince = [False] * (n + 1)
	princess = -1
	for i in range(n):
		b = [int(x) for x in stdin.readline().strip().split(' ')]
		married = False
		for j in b[1:]:
			if not prince[j]:
				prince[j] = True
				married = True
				break
		if not married:
			princess = i + 1
	if princess == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		res = -1
		for i in range(1, n + 1):
			if not prince[i]:
				res = i
		print(princess, res)


for _ in range(int(input())):
	n = int(input())
	p = [0] * (n + 1)
	for i in range(n):
		p[i + 1] = list(map(int, input().split()))[1:]
	t = [0] * (n + 1)
	m = [0] * (n + 1)
	for i in range(1, n + 1):
		for j in p[i]:
			if t[j] == 0:
				t[j] = 1
				m[i] = 1
				break
	if sum(m) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(m.index(0, 1), t.index(0, 1))


t = int(input())
for i in range(0, t):
	n = int(input())
	f = []
	for j in range(0, n):
		f.append(0)
	l1 = []
	for j in range(0, n):
		l = list(map(int, input().split()))
		c = l[0]
		l2 = l[1:1 + c]
		l1.append(l2)
	f1 = 0
	ans = []
	a1 = []
	c = 0
	for j in range(0, n):
		f2 = 0
		for k in range(0, len(l1[j])):
			if f[l1[j][k] - 1] == 0:
				f[l1[j][k] - 1] = 1
				f2 = 1
				break
		if f2 == 0:
			a1.append(j + 1)
			f1 = 1
	if f1 == 0:
		print('OPTIMAL')
	else:
		f2 = 0
		print('IMPROVE')
		for j in range(0, len(a1)):
			for k in range(0, n):
				if f[k] == 0:
					print(a1[j], k + 1)
					f2 = 1
					break
			if f2 == 1:
				break


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		l = list(map(int, input().split()))
		a.append(l[1:])
	v = [0] * (n + 1)
	rem = [0] * (n + 1)
	for i in range(len(a)):
		for j in range(len(a[i])):
			if v[a[i][j]] == 0:
				v[a[i][j]] = 1
				rem[i] = 1
				break
	v.pop(0)
	(x, y, z, cv, b) = (0, 0, 0, 0, 0)
	if v.count(1) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(len(rem)):
			if rem[i] == 0:
				print(i + 1, end=' ')
				break
		for i in range(len(v)):
			if v[i] == 0:
				print(i + 1)
				break


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		b = list(map(int, input().split()))
		del b[0]
		b.sort()
		a.append(b)
	c = dict()
	for j in range(len(a)):
		t = 0
		for s in a[j]:
			if s in c.keys():
				pass
			else:
				c[s] = 1
				t = 1
				break
		if t == 0:
			p = j + 1
	m = 0
	for j in range(1, n + 1):
		if j in c.keys():
			pass
		else:
			m = 1
			q = j
			break
	if m == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(p, q)


import sys
input = sys.stdin.readline
t = int(input())
for testcase in range(t):
	n = int(input())
	used = [True] * n
	p = -1
	q = -1
	for _ in range(n):
		a = list(map(int, input().split()))
		flag = True
		for i in range(a[0]):
			if flag and used[a[i + 1] - 1]:
				used[a[i + 1] - 1] = False
				flag = False
		if flag:
			p = _
	for i in range(n):
		if used[i]:
			q = i
			break
	if p == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(p + 1, q + 1)


T = int(input())
for t in range(T):
	N = int(input())
	ind = [0] * N
	pri = [0] * N
	A = []
	for n in range(N):
		A.append(list(map(int, input().split())))
	pos = 1
	k = 0
	for a in A:
		for i in range(1, a[0] + 1):
			if ind[a[i] - 1] == 0:
				ind[a[i] - 1] = 1
				pri[k] = 1
				break
		k += 1
	flag = 0
	for i in range(N):
		if pri[i] == 0:
			flag = i + 1
			break
	flag2 = 0
	for i in range(N):
		if ind[i] == 0:
			flag2 = i + 1
			break
	if flag == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(flag, flag2)


class Board:

	def __init__(self, size):
		self._size = size
		self._rows = set()
		self._columns = set()

	def is_free(self, col, row):
		return not (col in self._columns or row in self._rows)

	def lock(self, col, row):
		self._rows.add(row)
		self._columns.add(col)

	def find_free(self):
		if len(self._columns) == self._size:
			return None
		free_row = next((x for x in range(1, self._size + 1) if x not in self._rows))
		free_col = next((x for x in range(1, self._size + 1) if x not in self._columns))
		return (free_col, free_row)
task_number = int(input())
for _ in range(task_number):
	size = int(input())
	board = Board(size)
	for queen_index in range(1, size + 1):
		(_, *prince) = map(int, input().split())
		for col in prince:
			if board.is_free(col, queen_index):
				board.lock(col, queen_index)
				break
	free_cell = board.find_free()
	if free_cell is None:
		print('OPTIMAL')
	else:
		(prince, queen) = free_cell
		print('IMPROVE')
		print(queen, prince)


t = int(input())
for i in range(t):
	n = int(input())
	a = -1
	u = [False for i in range(n + 1)]
	for s in range(n):
		q = list(map(int, input().split()))
		e = q.pop(0)
		b = False
		for r in range(e):
			if not u[q[r]]:
				u[q[r]] = True
				b = True
				break
		if b == False:
			a = s + 1
	if a > 0:
		print('IMPROVE')
		for s in range(1, n + 1):
			if u[s] == False:
				print(a, s)
				break
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	l = [0] * (n + 1)
	p = []
	for i in range(n):
		b = list(map(int, input().split()))
		p.append(b[1:])
	f = []
	for i in range(n):
		c = 0
		for x in p[i]:
			if l[x] == 0:
				l[x] = 1
				c = 1
				break
		if c == 0:
			f.append([i + 1, p[i]])
	ll = []
	for i in range(1, n + 1):
		if l[i] == 0:
			ll.append(i)
	if ll == [] or f == []:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(f[0][0], ll[0])


t = int(input())
out = ''
while t > 0:
	t -= 1
	n = int(input())
	free = set([i for i in range(1, n + 1)])
	daughters = []
	for d in range(n):
		info = [int(i) for i in input().split(' ')]
		found = False
		for i in range(1, info[0] + 1):
			if info[i] in free:
				free.remove(info[i])
				found = True
				break
		if not found:
			daughters.append(d + 1)
	if len(daughters) == 0:
		out += 'OPTIMAL\n'
		continue
	out += f'IMPROVE\n{daughters[0]} {free.pop()}\n'
print(out)


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	unmarried_princess = -1
	n = int(stdin.readline())
	princess = [False for i in range(n)]
	for i in range(n):
		l = [int(k) - 1 for k in stdin.readline().split()][1:]
		for j in l:
			if not princess[j]:
				princess[j] = True
				break
		else:
			unmarried_princess = i
	if unmarried_princess == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		unmarried_prince = princess.index(False)
		print(unmarried_princess + 1, unmarried_prince + 1)


t = int(input())
for _ in range(t):
	k = int(input())
	items = []
	for i in range(k):
		item = list(map(int, input().split()))
		items.append(set(item[1:]))
	taken = set()
	index = 0
	for item in items:
		index += 1
		item = item - taken
		if len(item) == 0:
			sth = index
			continue
		x = min(item)
		taken.add(x)
	if len(taken) == k:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		all = set(range(1, k + 1))
		not_taken = list(all - taken)
		print(sth, not_taken[0])


from sys import stdin
input = stdin.readline
T = int(input())
for t in range(1, T + 1):
	is_married = dict()
	n = int(input())
	for j in range(1, n + 1):
		is_married[j] = 0
	improve_list = []
	for i in range(1, n + 1):
		_input = list(map(int, input().split()))
		should_improve = True
		for j in range(1, len(_input)):
			if is_married[_input[j]] == 0:
				is_married[_input[j]] = 1
		for j in range(1, len(_input)):
			if is_married[_input[j]] == 1 and should_improve == True:
				should_improve = False
				is_married[_input[j]] = -1
		if should_improve:
			improve_list.append(i)
	if len(improve_list) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for j in range(1, n + 1):
			if is_married[j] != -1:
				print(f'{improve_list[0]} {j}')
				break


for i in range(int(input())):
	kingdoms = int(input())
	not_married_queen = False
	taken = [False for i in range(kingdoms)]
	for queen in range(kingdoms):
		queen_married = False
		l = list(map(int, input().split()[1:]))
		for prefer_boi in l:
			if not taken[prefer_boi - 1]:
				taken[prefer_boi - 1] = True
				queen_married = True
				break
		if not queen_married:
			not_married_queen = str(queen)
	if not_married_queen:
		print('IMPROVE\n', int(not_married_queen) + 1, taken.index(False) + 1)
	else:
		print('OPTIMAL')


from sys import stdin, stdout
t = int(stdin.readline())
for i in range(t):
	female = set()
	male = set()
	n = int(stdin.readline())
	for k in range(n):
		female.add(k)
		male.add(k)
	for k in range(n):
		gl = list(map(int, stdin.readline().split()))
		g = gl.pop(0)
		for l in range(g):
			current = gl.pop(0) - 1
			if current in male:
				female.remove(k)
				male.remove(current)
				break
	if len(female) > 0:
		stdout.write('IMPROVE\n')
		stdout.write(str(female.pop() + 1) + ' ' + str(male.pop() + 1) + '\n')
	else:
		stdout.write('OPTIMAL\n')


t = int(input())
for rep in range(t):
	n = int(input())
	d = {}
	um = []
	for j in range(1, n + 1):
		temp = list(map(int, input().split()))
		f = 0
		for k in range(1, temp[0] + 1):
			if temp[k] not in d:
				d[temp[k]] = 0
				f = 1
				break
		if f == 0:
			um.append(j)
	if len(um) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for j in range(1, n + 1):
			if j not in d:
				print(um[0], j)
				break


t = int(input())
for _ in range(t):
	n = int(input())
	king = [0] * n
	ans = -1
	for i in range(n):
		a = list(map(int, input().split()))
		daughter_flag = False
		for j in range(a[0]):
			if king[a[j + 1] - 1] == 0:
				king[a[j + 1] - 1] = 1
				daughter_flag = True
				break
		if not daughter_flag:
			ans = i + 1
	if ans == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ans, king.index(0) + 1)


import sys
for noo in range(int(input())):
	n = int(input())
	se = set([i for i in range(1, n + 1)])
	ans = None
	for i in range(1, n + 1):
		s = map(int, sys.stdin.readline().split())
		s = list(s)[1:]
		remove = None
		for x in s:
			if x in se:
				se.remove(x)
				remove = True
				break
		if remove == None:
			ans = i
	if ans == None:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ans, se.pop())


t = int(input())
for _ in range(t):
	n = int(input())
	boys = [False] * (n + 1)
	dul = -1
	boys[0] = True
	chk = True
	for i in range(n):
		x = list(map(int, input().split()))
		for j in range(1, x[0] + 1):
			if boys[x[j]] == False:
				boys[x[j]] = True
				break
		else:
			if chk == True:
				dul = i + 1
				chk = False
	if dul != -1:
		print('IMPROVE')
		print(dul, boys.index(False))
	else:
		print('OPTIMAL')


from sys import stdin, exit, setrecursionlimit
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	g = [[]]
	n = int(input())
	for i in range(n):
		g.append(sorted(lmi()[1:]))
	bads = []
	done = [0] * (n + 1)
	for i in range(1, n + 1):
		found = False
		for j in g[i]:
			if not done[j]:
				done[j] = 1
				found = True
				break
		if not found:
			bads.append(i)
	fe = -1
	for i in range(1, n + 1):
		if done[i] == 0:
			fe = i
			break
	if fe == -1:
		print('OPTIMAL')
		continue
	else:
		print('IMPROVE')
		print(bads[0], fe)


import sys, threading
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)

def main():
	T = int(input())
	for i in range(T):
		n = int(input())
		g = [0] * (n + 1)
		g[0] = 1
		al = [[] for i in range(n + 1)]
		for j in range(n):
			l = list(map(int, input().split()))
			if l[0] == 0:
				pass
			else:
				al[j + 1] = l[1:]
		c = 0
		t = 0
		va1 = 0
		for b in range(1, n + 1):
			for e in al[b]:
				if g[e] == 0:
					g[e] = 1
					c = b
					break
			if c == b:
				pass
			else:
				t = 1
				va1 = b
		if t == 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			z = g.index(0)
			print(va1, z)
t = threading.Thread(target=main)
t.start()
t.join()


import sys
t = int(input())
for t_tmp in range(1, t + 1):
	n = int(input())
	marriage_list = []
	for i in range(n):
		tmp_list = input().split(' ')
		if int(tmp_list[0]) == 0:
			marriage_list.append([])
		else:
			marriage_list.append([int(s) for s in tmp_list[1:]])
	princesses = [0 for _ in range(n)]
	left_princesses = -1
	for i in range(n):
		found = False
		for j in marriage_list[i]:
			if princesses[j - 1] == 0:
				princesses[j - 1] = i + 1
				found = True
				break
		if not found and left_princesses == -1:
			left_princesses = i + 1
	if sum(princesses) == (1 + n) * n / 2:
		print('OPTIMAL')
	else:
		for (index, value) in enumerate(princesses):
			if value == 0:
				print('IMPROVE')
				print('{} {}'.format(left_princesses, index + 1))
				break


t = int(input())
for i in range(t):
	n = int(input())
	daughters = []
	array = [0] * n
	freeDaughter = 0
	for j in range(n):
		daughters.append([int(x) for x in input().split()[1:]])
	for j in range(len(daughters)):
		for k in range(len(daughters[j])):
			if array[daughters[j][k] - 1] == 1:
				if k == len(daughters[j]) - 1:
					freeDaughter = j + 1
				continue
			array[daughters[j][k] - 1] = 1
			break
		if len(daughters[j]) == 0:
			freeDaughter = j + 1
	for j in range(n):
		if array[j] == 0:
			print('IMPROVE\n' + str(freeDaughter) + ' ' + str(j + 1))
			break
	else:
		print('OPTIMAL')


def solve(k_g):
	seen = set()
	needs_partner = []
	for (i, options) in enumerate(k_g):
		requests = sorted(options[1:])
		found = False
		for j in range(len(requests)):
			if requests[j] not in seen:
				seen.add(requests[j])
				found = True
				break
		if not found:
			needs_partner.append(i + 1)
	if len(needs_partner) > 0:
		for i in range(len(k_g)):
			if i + 1 not in seen:
				return [needs_partner[0], i + 1]
	return None
for i in range(int(input())):
	n = int(input())
	k_g = [[int(x) for x in input().split()] for y in range(n)]
	result = solve(k_g)
	print('OPTIMAL' if result is None else 'IMPROVE')
	if result is not None:
		print('{} {}'.format(result[0], result[1]))


import sys
t = int(input())
for _ in range(t):
	g = []
	n = int(input())
	bad = [0 for i in range(n + 1)]
	for i in range(n):
		liste = list(map(int, input().split()))[1:]
		g.append(liste)
	done = False
	help = -1
	for i in range(n):
		if done:
			break
		found = False
		for j in g[i]:
			if not bad[j]:
				bad[j] = 1
				found = True
				break
		if not found:
			help = i + 1
	ans = -1
	for i in range(1, n + 1):
		if not bad[i]:
			ans = i
	if ans == -1 or help == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(help, ans)


from sys import stdin
t = int(input())
for i2 in range(t):
	n = int(input())
	check = [0] * (n + 1)
	ans = [0, 0, 0]
	for i in range(n):
		x = list(map(int, stdin.readline().split()))
		for j in range(0, x[0] + 1):
			if j > 0 and check[x[j]] == 0:
				check[x[j]] = 1
				break
			if j == x[0] and ans[0] == 0:
				ans[0] = 1
				ans[1] = i + 1
	if ans[0] == 0:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if check[i] == 0:
				ans[2] = i
				break
		print('IMPROVE')
		print(ans[1], ans[2])


for _ in range(int(input())):
	n = int(input())
	c = -1
	taken = [0] * (n + 1)
	m = 1
	for i in range(n):
		a = list(map(int, input().split()))
		f = 0
		for x in range(1, len(a)):
			if taken[a[x]] == 0:
				f = 1
				taken[a[x]] = 1
				break
		if f == 0:
			c = i + 1
	if c == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if taken[i] == 0:
				print('IMPROVE')
				print(c, i)
				break


for _ in range(int(input())):
	n = int(input())
	choices = []
	married = [0] * n
	for i in range(n):
		choices.append(list(map(int, input().split()))[1:])
	notMarried = []
	for i in range(n):
		if choices[i] != []:
			possible = True
			counter = 0
			cur = choices[i][counter] - 1
			while married[cur] != 0:
				counter += 1
				if counter >= len(choices[i]):
					possible = False
					break
				cur = choices[i][counter] - 1
			if possible:
				married[cur] = 1
				continue
		notMarried.append(i)
	if len(notMarried) == 0:
		print('OPTIMAL')
	else:
		for i in range(n):
			if married[i] == 0:
				print('IMPROVE')
				print(notMarried[0] + 1, i + 1)
				break


for _ in range(int(input())):
	n = int(input())
	pref = [0] * (n + 1)
	for i in range(n):
		pref[i + 1] = list(map(int, input().split()))[1:]
	taken = [0] * (n + 1)
	married = [0] * (n + 1)
	for i in range(1, n + 1):
		for prince in pref[i]:
			if taken[prince] == 0:
				taken[prince] = 1
				married[i] = 1
				break
	if sum(married) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(married.index(0, 1), taken.index(0, 1))


t = input()
for j in range(int(t)):
	p = int(input())
	dic0 = {}
	for q in range(p):
		st = input()
		nk = st.split(' ')
		if len(nk) > 1:
			dic0[q + 1] = nk[1:]
		else:
			dic0[q + 1] = [0]
	unm = []
	pr = [item for item in range(1, p + 1)]
	for item in dic0:
		married = False
		for item2 in dic0[item]:
			if pr[int(item2) - 1] == int(item2):
				pr[int(item2) - 1] = -1
				married = True
				break
		if not married:
			unm.append(item)
	if unm:
		print('IMPROVE')
		for item in pr:
			if item != -1:
				print(unm[0], item)
				break
	else:
		print('OPTIMAL')


ans = []
for _ in range(int(input())):
	n = int(input())
	u = []
	for i in range(n):
		s = list(map(lambda x: int(x) - 1, input().split()))
		u.append(s[1:])
	p = [0] * n
	g = [0] * n
	for i in range(n):
		for j in u[i]:
			if p[j] == 0:
				g[i] = 1
				p[j] = 1
				break
	if 0 not in p:
		ans.append('OPTIMAL')
	else:
		i1 = -1
		for i in range(n):
			if p[i] == 0:
				i1 = i
				break
		i2 = -1
		for i in range(n):
			if g[i] == 0:
				i2 = i
				break
		if i1 in u[i2]:
			a = 1 / 0
		ans.append('IMPROVE')
		ans.append(str(i2 + 1) + ' ' + str(i1 + 1))
print('\n'.join(ans))


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	n = int(sys.stdin.readline().strip())
	P = [-1] * (n + 1)
	x = -1
	for i in range(0, n):
		line = list(map(int, sys.stdin.readline().strip().split()))
		k = line[0]
		g = line[1:]
		v = False
		j = 0
		while v == False and j < k:
			if P[g[j]] == -1:
				P[g[j]] = i
				v = True
			else:
				j = j + 1
		if v == False:
			x = i
	if x == -1:
		print('OPTIMAL')
	else:
		y = 1
		while P[y] != -1:
			y = y + 1
		print('IMPROVE')
		print(str(x + 1) + ' ' + str(y))


from bisect import bisect_right as br
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	grid = []
	for i in range(n):
		(nk, *k) = map(int, input().split())
		grid += [k]
	dleft = []
	visited = dict()
	d = dict()
	left = []
	mar = [0] * (n + 1)
	ulta = dict()
	for i in range(n):
		flag = 0
		for j in range(len(grid[i])):
			if grid[i][j] not in visited:
				d[i + 1] = grid[i][j]
				ulta[grid[i][j]] = i + 1
				visited[grid[i][j]] = 1
				mar[grid[i][j]] = 1
				flag = 1
				break
		if flag == 0:
			left += [i]
	bnda = -1
	bndi = -1
	for i in range(1, n + 1):
		if mar[i] == 0:
			bnda = i
			flag = 1
			break
	done = dict()
	if len(left) != 0:
		bndi = left[0] + 1
		londa = bnda
	if bndi == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(bndi, londa)


kl = int(input())
for l in range(kl):
	n = int(input())
	N = set(range(1, n + 1))
	G = set(range(1, n + 1))
	for kn in range(n):
		(sc, pr) = (0, 0)
		for i in input().split():
			sc += 1
			if sc == 1 or pr:
				continue
			if int(i) in G:
				pr = 1
				G.remove(int(i))
				N.remove(kn + 1)
	if len(G) > 0:
		print('IMPROVE')
		for i in N:
			print(i, '', end='')
			break
		for i in G:
			print(i)
			break
	else:
		print('OPTIMAL')


t = int(input())
for t1 in range(0, t):
	n = int(input())
	p = [0] * (n + 2)
	pr = [0] * (n + 2)
	y = 1
	ans = []
	for i in range(0, n):
		x = list(map(int, input().split()))
		f = 0
		for j in range(1, x[0] + 1):
			if p[x[j]] == 0:
				p[x[j]] = 1
				pr[i + 1] = 1
				f = 1
				break
		if f == 0:
			y = 0
			ans.append(i + 1)
	av = -1
	for i in range(1, n + 1):
		if p[i] == 0:
			av = i
			break
	if av != -1:
		print('IMPROVE')
		print(ans[0], av)
	else:
		print('OPTIMAL')


import collections
test = int(input())
for _ in range(test):
	n = int(input())
	graph = collections.defaultdict(list)
	for i in range(1, n + 1):
		arr = list(map(int, input().split()))
		graph[i] = arr[1:]
	vism = [0] * (n + 1)
	visf = [0] * (n + 1)
	for i in range(1, n + 1):
		if visf[i] == 0:
			for j in graph[i]:
				if vism[j] == 0:
					vism[j] = 1
					visf[i] = 1
					break
	if sum(visf) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(visf.index(0, 1), vism.index(0, 1))


from math import *
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()
from bisect import bisect_left

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1
from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	m = [0] * (n + 1)
	want = {}
	dum = []
	for i in range(n):
		want[i + 1] = [int(j) for j in input().split()][1:]
		f = 0
		for j in want[i + 1]:
			if m[j] == 0:
				m[j] = 1
				f = 1
				break
		if f == 0:
			dum += [i + 1]
	kum = []
	for i in range(1, n + 1):
		if m[i] == 0:
			kum += [i]
	if kum == []:
		print('OPTIMAL')
	else:
		f = 0
		for i in kum:
			for j in dum:
				if bs(want[j], i) == -1:
					f = 1
					print('IMPROVE')
					print(j, i)
					break
			if f == 1:
				break
		if f == 0:
			print('OPTIMAL')


def f1():
	import math as m
	T = int(input())
	for i in range(0, T):
		NK = [int(j) for j in input().split(' ')]
		N = NK[0]
		K = NK[1]
		if N % 2 != 0:
			if K % 2 == 0:
				print('NO')
			else:
				sqrt = int(m.sqrt(N))
				if sqrt % 2 == 0:
					sqrt = sqrt - 1
				if 1 <= K <= sqrt:
					print('YES')
				else:
					print('NO')
		elif N % 2 == 0:
			if K % 2 != 0:
				print('NO')
			else:
				sqrt = int(m.sqrt(N))
				if sqrt % 2 != 0:
					sqrt = sqrt - 1
				if 2 <= K <= sqrt:
					print('YES')
				else:
					print('NO')

def f2():
	T = int(input())
	while T != 0:
		T = T - 1
		N = int(input())
		Matrix = list()
		Number = list()
		flag1 = True
		for i in range(0, N):
			l = [int(j) for j in input().split(' ')]
			Matrix.append(l[1:])
			Number.append(l[0])
			if l[0] != N and flag1 == True:
				flag1 = False
		pr = [False] * N
		if flag1 == True:
			print('OPTIMAL')
		else:
			qu = [False] * N
			da = 0
			for i in range(0, len(Matrix)):
				for j in range(0, len(Matrix[i])):
					if pr[Matrix[i][j] - 1] == False:
						da = da + 1
						pr[Matrix[i][j] - 1] = True
						qu[i] = True
						break
			if da == N:
				print('OPTIMAL')
			else:
				flag = False
				for i in range(0, len(qu)):
					if flag == True:
						break
					if qu[i] == False:
						for j in range(0, len(pr)):
							if pr[j] == False:
								print('IMPROVE')
								print(str(i + 1) + str(' ') + str(j + 1))
								flag = True
								break
f2()


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def main():
	for _ in range(int(INPUT())):
		n = int(INPUT())
		free = [1] * n
		unmarried = -1
		for i in range(n):
			l = list(map(int, INPUT().split()))
			for prince in l[1:]:
				if free[prince - 1]:
					free[prince - 1] = 0
					break
			else:
				unmarried = i + 1
		if unmarried == -1:
			PRINT('OPTIMAL\n')
		else:
			PRINT('IMPROVE\n')
			unmarried_prince = free.index(1) + 1
			PRINT('%d %d\n' % (unmarried, unmarried_prince))
main()


t = int(input())
for i in range(t):
	n = int(input())
	dl = []
	for j in range(n):
		(k, *g) = [int(x) for x in input().split()]
		if k:
			dl.append(g)
		else:
			dl.append([])
	taken = set()
	optimal_daughter = None
	for (i, l) in enumerate(dl):
		for j in l:
			if j not in taken:
				taken.add(j)
				break
		else:
			optimal_daughter = i
	if len(taken) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(optimal_daughter + 1, list(set(range(1, n + 1)) - taken)[0])


t = int(input())
for _ in range(t):
	n = int(input())
	v = [0] * n
	married = 0
	g = [0] * n
	for i in range(1, n + 1):
		a = list(map(int, input().split()))[1:]
		for k in a:
			if v[k - 1] == 0:
				v[k - 1] = 1
				g[i - 1] = 1
				married += 1
				break
	if married == n:
		print('OPTIMAL')
	else:
		for j in range(n):
			if v[j] == 0:
				print('IMPROVE')
				break
		for k in range(n):
			if g[k] == 0:
				break
		print(k + 1, j + 1)


import atexit
import io
import sys
buff = io.StringIO()
sys.stdout = buff

@atexit.register
def write():
	sys.__stdout__.write(buff.getvalue())
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = []
	i = 0
	while i < n:
		s.append(input())
		i = i + 1
	temp = [i + 1 for i in range(n)]
	b = [0 for i in range(n)]
	daughter = [0 for i in range(n)]
	couple = []
	no = 0
	for i in s:
		i = i.split()
		ele = int(i[0])
		for j in range(ele):
			if b[int(i[j + 1]) - 1] == 0:
				couple.append(int(i[j + 1]))
				b[int(i[j + 1]) - 1] = 1
				daughter[no] = 1
				break
		no += 1
	if len(couple) == n:
		print('OPTIMAL')
	elif len(couple) == 0:
		print('IMPROVE')
		print(1, 1)
	else:
		print('IMPROVE')
		d = -1
		p = -1
		for i in range(len(b)):
			if b[i] == 0:
				p = i + 1
				break
		for i in range(len(daughter)):
			if daughter[i] == 0:
				d = i + 1
				break
		print(d, p)


from sys import stdin
try:
	for _ in range(int(input())):
		n = int(input())
		marriage = [False] * (n + 1)
		married = [False] * (n + 1)
		count = 0
		d = {}
		for i in range(1, n + 1):
			d[i] = sorted([int(i) for i in stdin.readline().split()][1:])
			for j in d[i]:
				if marriage[j] == False:
					marriage[j] = True
					married[i] = True
					count += 1
					break
		if count == n:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(married.index(False, 1), marriage.index(False, 1))
except Exception as e:
	print(e)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	used = set()
	lonely = []
	for d in range(1, n + 1):
		l = list(map(int, input().split()))[1:]
		for k in l:
			if k not in used:
				used.add(k)
				break
		else:
			lonely.append(d)
	if len(lonely):
		print('IMPROVE')
		k = 1
		while k in used:
			k += 1
		print(lonely[0], k)
	else:
		print('OPTIMAL')


t = int(input())
s = []
while t:
	t -= 1
	n = int(input())
	a = [0 for i in range(n)]
	d = [True for i in range(n)]
	for i in range(n):
		ok = True
		for ij in input().split():
			if not ok:
				j = int(ij)
				if d[j - 1]:
					d[j - 1] = False
					a[i] = 1
					break
			ok = False
	sol = []
	d = [i + 1 for i in range(n) if d[i]]
	a = [i + 1 for i in range(n) if a[i] == 0]
	if a == [] or d == []:
		s.append(['OPTIMAL'])
	else:
		n = len(a)
		m = len(d)
		i = 0
		j = 0
		while i < n and j < m:
			sol.append([a[i], d[j]])
			break
			i += 1
			j += 1
		s.append(['IMPROVE', sol])
for i in s:
	if len(i) == 1:
		print(*i)
	else:
		print(i[0])
		for j in i[1]:
			print(*j)


for _ in range(int(input())):
	used = set()
	f = 0
	lo = {}
	n = int(input())
	ms = {i for i in range(1, n + 1)}
	for j in range(1, n + 1):
		loves = list(map(int, input().split()))
		if loves[0] != 0:
			loves = loves[1:]
		for i in loves:
			if i not in used and i != 0:
				used.add(i)
				break
		else:
			f = 1
			lo[j] = set(loves)
	if f == 1:
		for i in lo:
			if ms - lo[i] - used:
				print('IMPROVE')
				print(i, list(ms - lo[i] - used)[0])
				break
	else:
		print('OPTIMAL')


from sys import stdin, stdout
import traceback
read = stdin.readline
write = stdout.write
writeln = lambda x: write(str(x) + '\n')

def reads(typ=int):
	return list(map(typ, read().split()))

class Sol:

	@classmethod
	def input(cls):
		s = cls()
		return s

	def solve(self):
		n = int(read())
		picked = [False] * n
		pity_princess = []
		for i in range(n):
			tmp = reads()
			k = tmp[0]
			gs = tmp[1:]
			gs = [g - 1 for g in gs]
			for g in gs:
				if not picked[g]:
					picked[g] = True
					break
			else:
				pity_princess.append(i)
		if not pity_princess:
			return None
		rest_princes = [i for (i, p) in enumerate(picked) if not p]
		assert rest_princes
		return (pity_princess[-1] + 1, rest_princes[-1] + 1)
try:
	for _ in range(int(read())):
		res = Sol.input().solve()
		if res is None:
			writeln('OPTIMAL')
		else:
			writeln('IMPROVE')
			writeln('{} {}'.format(res[0], res[1]))
except Exception as e:
	print('Got exception:', repr(e))
	print(traceback.format_exc())


testCases = int(input())
for i1 in range(testCases):
	length = int(input())
	daughterList = []
	princeMarried = [False] * length
	daughterMarried = [False] * length
	for i in range(length):
		temp = list(map(int, input().split()))
		daughterList.append(temp)
	for i2 in range(length):
		for i3 in range(1, daughterList[i2][0] + 1, 1):
			if not princeMarried[daughterList[i2][i3] - 1]:
				princeMarried[daughterList[i2][i3] - 1] = True
				daughterMarried[i2] = True
				break
	if False in princeMarried:
		print('IMPROVE')
		print(daughterMarried.index(False) + 1, princeMarried.index(False) + 1)
	else:
		print('OPTIMAL')


for i in range(int(input())):
	n = int(input())
	A = list(range(1, n + 1))
	B = list(range(1, n + 1))
	couples = {}
	for j in range(n):
		s = list(map(int, input().split()))
		for k in range(1, s[0] + 1):
			if couples.get(s[k], 0) == 0:
				couples[s[k]] = j + 1
				break
	if len(couples) < n:
		print('IMPROVE')
		print(str(min(list(set(A).difference(couples.values())))) + ' ' + str(min(list(set(B).difference(couples.keys())))))
	else:
		print('OPTIMAL')


import sys

def ria():
	return list(map(int, input().split(' ')))
sys.setrecursionlimit(10 ** 9)

def solve():
	t = ria()[0]
	for tt in range(t):
		n = ria()[0]
		used = [False] * (n + 1)
		assigned = [False] * (n + 1)
		lis = [[] for x in range(n + 1)]
		for nn in range(1, n + 1):
			lis[nn] = ria()
		ans = 0
		notAssignedOne = -1
		for nn in range(1, n + 1):
			for i in range(1, len(lis[nn])):
				a = lis[nn][i]
				if not used[a]:
					used[a] = True
					ans += 1
					assigned[nn] = True
					break
			if not assigned[nn]:
				notAssignedOne = nn
		if n == ans:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			for mm in range(1, n + 1):
				if not used[mm]:
					print(notAssignedOne, mm)
					break
	pass
solve()


def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		n = int(input())
		married = [0] * (n + 1)
		married[0] = 1
		ans = -1
		for i in range(n):
			(k, *l) = map(int, input().split())
			flag = 0
			for j in range(k):
				if married[l[j]] == 0:
					married[l[j]] = 1
					flag = 1
					break
			if flag == 0:
				ans = i + 1
		if ans == -1:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			for i in range(1, n + 1):
				if married[i] == 0:
					print(ans, i)
					break
main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	g = [[] for i in range(n + 1)]
	p = [0 for i in range(n + 1)]
	for i in range(n):
		g[i + 1] = list(rint())
	unmarried = 0
	for i in range(1, n + 1):
		for j in range(1, g[i][0] + 1):
			if p[g[i][j]] == 0:
				p[g[i][j]] = 1
				break
		else:
			unmarried = i
	if unmarried == 0:
		print('OPTIMAL')
		continue
	print('IMPROVE')
	for i in range(1, n + 1):
		if p[i] == 0:
			print(unmarried, i)
			break


from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		dl = []
		for _ in range(n):
			dl.append(list(RL())[1:])
		rec = set()
		a = []
		for (i, arr) in enumerate(dl):
			for j in arr:
				if j not in rec:
					rec.add(j)
					break
			else:
				a.append(i + 1)
		if not a:
			print('OPTIMAL')
		else:
			b = -1
			for i in range(1, n + 1):
				if i not in rec:
					b = i
					break
			print('IMPROVE')
			print(a[0], b)
main()


t = int(input())
for i in range(t):
	n = int(input())
	daught = []
	for i in range(n):
		l = list(map(int, input().split()))
		l = l[1:]
		daught.append(l)
	marr = [False] * n
	used = []
	for i in range(n):
		used.append(0)
	min1 = 1
	c = 0
	sad = 0
	curr_ans = -1
	for i in daught:
		for k in i:
			if used[k - 1] == 0:
				used[k - 1] = 1
				if k == min1:
					min1 = k + 1
				marr[c] = True
				break
		c += 1
	m1 = -1
	for i in range(n):
		if used[i] == 0:
			m1 = i + 1
			break
	m2 = -1
	for i in range(n):
		if marr[i] == False:
			m2 = i + 1
			break
	if m2 == -1 or m1 == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(m2, m1)


from collections import *
from sys import *
for _ in range(int(input())):
	d = defaultdict(lambda : 0)
	n = int(stdin.readline())
	c = []
	for i in range(n):
		a = [int(x) for x in stdin.readline().split()]
		s = a[0]
		for j in range(1, len(a)):
			if d[a[j]] == 0:
				d[a[j]] = 1
				break
		else:
			c.append(i)
	if len(c) == 0:
		stdout.write('OPTIMAL' + '\n')
	else:
		stdout.write('IMPROVE' + '\n')
		h = -1
		for i in range(1, n + 1):
			if d[i] == 0:
				h = i
				break
		stdout.write(str(c[0] + 1) + ' ' + str(h) + '\n')


from sys import exit
for t in range(int(input())):
	n = int(input())
	d = {}
	king = [0 for i in range(n)]
	daug = [0 for i in range(n)]
	for i in range(n):
		K = list(map(int, input().split()))
		d[i] = K[1:]
		for j in d[i]:
			if king[j - 1] == 0:
				king[j - 1] = 1
				daug[i] = 1
				break
	flag = 0
	for i in range(n):
		if daug[i] == 0:
			for j in range(n):
				if king[j] == 0:
					print('IMPROVE')
					print(i + 1, j + 1)
					flag = 1
					break
			break
	if flag == 0:
		print('OPTIMAL')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = stdin.readline()
	n = int(n)
	l = []
	taken = set()
	taken2 = set()
	girls = [i + 1 for i in range(n)]
	boys = set(girls)
	girls = set(girls)
	for k in range(n):
		l.append([int(i) for i in stdin.readline().split()])
	for i in range(n):
		for j in range(1, len(l[i])):
			if l[i][j] not in taken:
				taken.add(l[i][j])
				taken2.add(i + 1)
				break
	boys = boys.difference(taken)
	girls = girls.difference(taken2)
	(ans1, ans2) = (-1, -1)
	for i in boys:
		ans2 = i
	for i in girls:
		ans1 = i
	if ans1 == -1 and ans2 == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		stdout.write(str(ans1) + ' ' + str(ans2) + '\n')


from sys import stdin
input = stdin.readline
q = int(input())
for rweur in range(q):
	n = int(input())
	l = [0]
	for i in range(n):
		s = list(map(int, input().split()))
		l.append(s)
	assign = [-1] * (n + 1)
	for i in range(1, n + 1):
		j = 1
		while j <= l[i][0]:
			if assign[l[i][j]] == -1:
				assign[l[i][j]] = i
				break
			else:
				j += 1
	dupa = True
	for i in range(1, n + 1):
		if assign[i] == -1:
			dupa = False
			kutacz = i
	if dupa:
		print('OPTIMAL')
	else:
		pres = [0] * (n + 1)
		for i in range(1, n + 1):
			if assign[i] != -1:
				pres[assign[i]] = 1
		for i in range(1, n + 1):
			if pres[i] == 0:
				dupsko = i
				break
		print('IMPROVE')
		print(dupsko, kutacz)


for i in range(int(input())):
	am = int(input())
	govs = [True] * am
	arr = []
	for i in range(am):
		newArr = list(map(int, input().split()))
		arr.append(newArr[1:])
	for i in range(am):
		for g in range(len(arr[i])):
			if govs[arr[i][g] - 1]:
				govs[arr[i][g] - 1] = False
				arr[i] = False
				break
	if not True in govs:
		print('OPTIMAL')
	else:
		for i in range(am):
			if arr[i] != False:
				for g in range(am):
					if govs[g]:
						print('IMPROVE')
						print(i + 1, g + 1)
						break
				break


t = int(input())
for i in range(t):
	n = int(input())
	if n > 0:
		prince = []
		order = []
		m = []
		for j in range(n):
			prince.append(True)
			a = input()
			a = list(map(int, a.split()))
			m.append(a[0])
			x = a[1:]
			x.sort()
			order.append(x)
		num = -1
		num_flag = 0
		for k in range(n):
			flag = 1
			if len(order[k]) == 0:
				num = k
				num_flag = 1
			for elt in order[k]:
				if prince[elt - 1]:
					prince[elt - 1] = False
					flag = 0
					break
			if flag:
				num = k
				num_flag = 1
		if num_flag:
			print('IMPROVE')
			ans = -1
			for j in range(n):
				if prince[j]:
					ans = j
					break
			print(num + 1, ans + 1)
		else:
			print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	m1 = [-1] * n
	m2 = [-1] * n
	l = []
	for j in range(n):
		l.append(list(map(int, input().split())))
		for k in range(l[j][0]):
			if m2[l[j][k + 1] - 1] == -1:
				m1[j] = 1
				m2[l[j][k + 1] - 1] = 1
				break
	if -1 in m1:
		x = m1.index(-1)
	else:
		x = -1
	if -1 in m2:
		y = m2.index(-1)
	else:
		y = -1
	if x == -1 or y == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(str(x + 1) + ' ' + str(y + 1))


t = int(input())
for i in range(t):
	val = 0
	n = int(input())
	prn = [0 for k in range(n)]
	for j in range(n):
		arr = list(map(int, input().split()))
		del arr[0]
		for k in arr:
			if prn[k - 1] == 0:
				prn[k - 1] = -1
				break
		else:
			if val == 0:
				val = j + 1
	if val == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for (j, k) in enumerate(prn):
			if k == 0:
				print(str(val) + ' ' + str(j + 1))
				break


for j in range(int(input())):
	n = int(input())
	married = list()
	unmarrid = 0
	for a in range(n):
		princes = list(map(int, input().split()))
		married.append(princes)
	yescupl = [0 for a in range(n + 1)]
	for a in range(n):
		got = False
		for b in range(1, len(married[a])):
			if yescupl[married[a][b]] == 0:
				got = True
				yescupl[married[a][b]] = 1
				break
		if not got:
			unmarrid = a + 1
	if unmarrid > 0:
		for a in range(1, n + 1):
			if yescupl[a] == 0:
				print('IMPROVE')
				print(unmarrid, a)
				break
	else:
		print('OPTIMAL')


for i in range(int(input())):
	n = int(input())
	dic = {}
	se = set()
	for i in range(1, n + 1):
		dic[i] = 0
		se.add(i)
	j = 1
	output = 'OPTIMAL'
	for i in range(n):
		lis = list(map(int, input().split()))
		length = len(lis)
		for i in range(1, length):
			if dic[j] != lis[i] and lis[i] in se:
				dic[j] = lis[i]
				se.remove(lis[i])
				break
		if dic[j] == 0:
			output = 'IMPROVE'
			kuvari = j
		j += 1
	if output == 'IMPROVE':
		print('IMPROVE')
		print(kuvari, end=' ')
		print(se.pop())
	else:
		print('OPTIMAL')


from sys import stdin, stdout

def main():
	t = int(input())
	for __ in range(t):
		n = int(stdin.readline())
		kings = [False] * n
		exist = False
		flag = False
		not_married = -1
		for l in range(n):
			married = False
			k = [int(x) - 1 for x in stdin.readline().split()][1:]
			for h in k:
				if not kings[h]:
					married = True
					kings[h] = True
					break
			if not married:
				not_married = l + 1
				exist = True
		if exist:
			for i in range(n):
				if not kings[i]:
					stdout.write('IMPROVE\n' + str(not_married) + ' ' + str(i + 1) + '\n')
					break
		else:
			stdout.write('OPTIMAL\n')
main()


def main():
	import sys
	input = sys.stdin.readline
	T = int(input())
	for t in range(T):
		N = int(input())
		seen = [0] * (N + 1)
		lines = []
		for i in range(1, N + 1):
			lines.append(list(map(int, input().split())))
		ii = 0
		for i in range(1, N + 1):
			line = lines[i - 1][1:]
			flg = 1
			for j in line:
				if not seen[j]:
					flg = 0
					seen[j] = 1
					break
			if flg:
				ii = i
		if ii:
			for j in range(1, N + 1):
				if not seen[j]:
					print('IMPROVE')
					print(ii, j)
					break
		else:
			print('OPTIMAL')
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	v = [True] * n
	for i in range(n):
		(k, *a) = map(int, input().split())
		for x in a:
			if v[x - 1]:
				v[x - 1] = False
				break
		else:
			p = i
	for j in range(n):
		if v[j]:
			print('IMPROVE')
			print(p + 1, j + 1)
			break
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	rem = -1
	a = [0] * (n + 1)
	for (i, (k, *l)) in enumerate((map(int, input().split()) for _ in range(n))):
		for j in l:
			if a[j] == 0:
				a[j] = 1
				break
		else:
			rem = i + 1
	if rem == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if a[i] == 0:
				print(rem, i)
				break
		else:
			raise Exception('hogehoge')


import bisect
import math
import itertools
import sys
alpha = 'abcdefghijklmnopqrstuvwxyz'

def solve(n):
	girls = []
	for i in range(n):
		arr = [int(x) for x in input().split()]
		girls.append(arr[1:])
	boys = [x for x in range(1, n + 1)]
	gs = [x for x in range(1, n + 1)]
	rem_girls = set(gs)
	rem_boys = set(boys)
	for (ind, girl) in enumerate(girls):
		for boy in girl:
			if boy in rem_boys:
				rem_boys.remove(boy)
				rem_girls.remove(ind + 1)
				break
	if rem_boys and rem_girls:
		return ['IMPROVE', str(max(list(rem_girls))) + ' ' + str(min(list(rem_boys)))]
	else:
		return ['OPTIMAL']
	pass
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	ans.append(solve(n))
for test in ans:
	for answer in test:
		print(answer)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	p = []
	for i in range(n):
		p.append(list(map(int, sys.stdin.readline().split())))
	(prince, princess, rem) = ([False] * (n + 1), [False] * (n + 1), [])
	for i in range(n):
		for j in range(1, len(p[i])):
			if not prince[p[i][j]]:
				prince[p[i][j]] = True
				princess[i] = True
				break
		if not princess[i]:
			rem.append(i + 1)
	if len(rem) == 0:
		print('OPTIMAL')
	else:
		v = -1
		for i in range(1, n + 1):
			if not prince[i]:
				v = i
				break
		print('IMPROVE')
		print(rem[0], v)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
import datetime
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(int(input())):
		n = int(input())
		d = {}
		for i in range(n):
			a = [int(x) for x in input().split()]
			k = a[0]
			g = a[1:]
			mi = 999999999999
			t = 0
			for j in g:
				if j in d:
					continue
				else:
					mi = min(j, mi)
					t = 1
			if t == 0:
				q = i + 1
			d[mi] = 1
		z = 0
		for i in range(1, n + 1):
			if i not in d:
				print('IMPROVE')
				print(q, i)
				z = 1
				break
		if z == 0:
			print('OPTIMAL')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	married = [False for _ in range(n)]
	gs = [[] for _ in range(n)]
	for i in range(n):
		ks = list(map(int, input().split()))[1:]
		for k in ks:
			gs[i].append(k - 1)
	d = -1
	for (i, g) in enumerate(gs):
		for gi in g:
			if not married[gi]:
				married[gi] = True
				break
		else:
			d = i
	if all(married):
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for (i, m) in enumerate(married):
			if not m:
				print(d + 1, i + 1)
				break


from pprint import pprint
for _ in range(int(input())):
	choices = []
	n = int(input())
	for _ in range(n):
		li = list(map(int, input().split()))[1:]
		choices.append(li)
	taken = [False] * (n + 1)
	princess = [False] * n
	couples = 0
	for (p, choice) in enumerate(choices):
		married = False
		for c in choice:
			if not taken[c]:
				taken[c] = True
				couples += 1
				married = True
				break
		princess[p] = married
	if couples == n:
		print('OPTIMAL')
	else:
		nt = 1
		while taken[nt]:
			nt += 1
		for (i, p) in enumerate(princess):
			if not p:
				print('IMPROVE')
				print(i + 1, nt)
				break


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	array = []
	for __ in range(n):
		array.append(sorted(list(map(int, input().split()))[1:]))
	kdms = {i for i in range(1, n + 1)}
	dick = {}
	for i in range(n):
		dick[i] = -1
		for j in array[i]:
			if j in kdms:
				kdms.remove(j)
				dick[i] = j
				break
	ans = 'OPTIMAL'
	anst = None
	for i in range(n):
		if dick[i] == -1:
			this = set(array[i])
			rem = kdms.difference(this)
			if len(rem) > 0:
				ans = 'IMPROVE'
				anst = (i + 1, list(rem)[0])
				break
	print(ans)
	if anst != None:
		print(*anst)


from sys import stdin, stdout
t = int(stdin.readline())
for query in range(t):
	n = int(stdin.readline())
	a = []
	for x in range(n):
		b = stdin.readline().split()
		b[0] = int(b[0])
		for y in range(b[0]):
			b[y + 1] = int(b[y + 1])
		a.append(b)
	b = []
	c = []
	d = 0
	for x in range(n):
		b.append(1)
	for x in range(n):
		for y in range(a[x][0]):
			if b[a[x][y + 1] - 1] == 1:
				b[a[x][y + 1] - 1] = 0
				break
			elif y == a[x][0] - 1:
				c.append(x)
		if a[x][0] == 0:
			c.append(x)
	for x in range(n):
		if b[x] == 1:
			d = x
			break
	if len(c) > 0:
		stdout.write('IMPROVE\n')
		stdout.write(str(c[0] + 1) + ' ' + str(d + 1) + '\n')
	else:
		stdout.write('OPTIMAL\n')


for _ in range(int(input())):
	N = int(input())
	arr = [list(map(int, input().split()[1:])) for _ in range(N)]
	price = set(range(1, N + 1))
	not_married = None
	for (idx, choice) in enumerate(arr):
		unmarried = True
		for ch in choice:
			if ch in price:
				price.discard(ch)
				unmarried = False
				break
		if unmarried:
			not_married = idx
	if not_married is not None and price:
		print('IMPROVE')
		print(not_married + 1, list(price)[0])
	else:
		print('OPTIMAL')


from sys import *
input = stdin.readline
for u in range(int(input())):
	n = int(input())
	l = [0] * n
	x = -1
	for i in range(n):
		d = list(map(int, input().split()))[1:]
		f = 0
		for j in d:
			if l[j - 1] == 0:
				l[j - 1] = 1
				f = 1
				break
		if f == 0:
			x = i + 1
	if x == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		y = l.index(0) + 1
		print(x, y)


T = int(input())
for t in range(T):
	K = int(input())
	s1 = [False] * K
	s2 = [False] * K
	for k in range(K):
		l = list(map(int, input().split()))[1:]
		for ll in l:
			if not s2[ll - 1]:
				s2[ll - 1] = True
				s1[k] = True
				break
	s1f = next((res for (res, val) in enumerate(s1) if val == False), -1)
	s2f = next((res for (res, val) in enumerate(s2) if val == False), -1)
	if s1f == -1 or s2f == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(str(s1f + 1) + ' ' + str(s2f + 1))


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	d = {}
	res = True
	for j in range(1, n + 1, 1):
		a = list(map(int, input('').split(' ')))
		k = a[0]
		for i in range(1, 1 + k, 1):
			if a[i] not in d:
				d[a[i]] = 0
				break
		else:
			if res:
				ans = j
				res = False
	if res:
		print('OPTIMAL')
		continue
	for i in range(1, n + 1, 1):
		if i not in d:
			break
	print('IMPROVE')
	print(str(ans) + ' ' + str(i))


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque
import bisect as bi
import heapq as hq

def I():
	return int(input())

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

def main():
	try:
		for _ in range(int(input())):
			n = int(input())
			d = {}
			ans = []
			for x in range(1, n + 1):
				d[x] = 1
			for i in range(n):
				temp = list(map(int, input().split()))
				temp.pop(0)
				temp.sort()
				q = 0
				for x in temp:
					if d.get(x, 0) != 0:
						d[x] = 0
						q = 1
						break
				if q == 0:
					ans.append(i)
				else:
					continue
			if len(ans) == 0:
				print('OPTIMAL')
			else:
				lop = -1
				for x in d.keys():
					if d[x] == 1:
						lop = x
						break
				if lop != -1:
					print('IMPROVE')
					print(ans[0] + 1, lop)
				else:
					print('OPTIMAL')
	except:
		pass
M = 998244353
P = 1000000007
main()


t = int(input())
for a in range(t):
	n = int(input())
	princes = [0] * n
	single = 0
	for i in range(n):
		for j in [int(i) for i in input().split()][1:]:
			if princes[j - 1]:
				continue
			princes[j - 1] = 1
			break
		else:
			single = i + 1
	if single == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if princes[i] == 0:
				print('{} {}'.format(single, i + 1))
				break


t = int(input())
while t:
	flag = True
	n = int(input())
	dp = [-1 for _ in range(n)]
	temp = 1000000
	for j in range(n):
		falg2 = False
		array = list(map(int, input().split()))
		for i in range(1, len(array)):
			if dp[array[i] - 1] == -1:
				dp[array[i] - 1] = j
				falg2 = True
				break
		if not falg2:
			temp = min(j, temp)
	for i in range(n):
		if dp[i] == -1:
			print('IMPROVE')
			print(temp + 1, i + 1)
			flag = False
			break
	if flag:
		print('OPTIMAL')
	t -= 1


count = int(input())
for i in range(count):
	n = int(input())
	princesses = list()
	princes = [True for j in range(n)]
	for j in range(n):
		for candidate in list(map(int, input().split()))[1:]:
			if princes[candidate - 1]:
				princes[candidate - 1] = False
				princesses.append(True)
				break
		else:
			princesses.append(False)
	if False in princesses:
		print('IMPROVE')
		princesses.reverse()
		frm = n - princesses.index(False)
		to = princes.index(True) + 1
		print(f'{frm} {to}')
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline
for t in range(int(input())):
	n = int(input())
	d = [0] * (n + 1)
	g = [0] * (n + 1)
	for i in range(1, n + 1):
		P = [int(num) for num in input().split()[1:]]
		for p in P:
			if not g[p]:
				d[i] = 1
				g[p] = 1
				break
	c1 = 0
	c2 = 0
	for dt in range(n, 0, -1):
		if not d[dt]:
			c1 = dt
			break
	for pc in range(n, 0, -1):
		if not g[pc]:
			c2 = pc
			break
	if not c1:
		print('OPTIMAL')
		continue
	print('IMPROVE')
	print('{} {}'.format(c1, c2))


for i in range(int(input())):
	n = int(input())
	list1 = []
	for i in range(n):
		a = [int(x) for x in input().split()]
		a.remove(a[0])
		list1.append(a)
	list2 = []
	for i in range(n):
		list2.append(0)
	evde_kalan_kiz = []
	for i in range(len(list1)):
		x = 0
		for j in list1[i]:
			if list2[j - 1] != 1:
				list2[j - 1] = 1
				x += 1
				break
		if x == 0:
			evde_kalan_kiz.append(i + 1)
	evde_kalan_erkek = []
	for i in range(len(list2)):
		if list2[i] == 0:
			evde_kalan_erkek.append(i + 1)
	if len(evde_kalan_erkek) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(evde_kalan_kiz[0], evde_kalan_erkek[0])


import sys
input = sys.stdin.readline
for ti in range(int(input().strip())):
	n = int(input().strip())
	(p, d) = ([0] * n, [-1] * n)
	for ni in range(n):
		k = [int(x) for x in input().strip().split()][1:]
		k.sort()
		for ki in k:
			if not p[ki - 1]:
				p[ki - 1] = 1
				d[ni] = ki
				break
	(fd, fp) = (-1, -1)
	for i in range(n):
		if d[i] == -1:
			fd = i
			break
	for i in range(n):
		if not p[i]:
			fp = i
			break
	if fd == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(fd + 1, fp + 1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	gh = list()
	gh.append([])
	for i in range(0, n):
		l = list(map(int, input().split()))
		gh.append(l)
	boys = [False] * (n + 1)
	girls = [False] * (n + 1)
	cnt_boys = 0
	for i in range(1, n + 1):
		for j in gh[i][1:]:
			if not boys[j]:
				boys[j] = True
				girls[i] = True
				cnt_boys += 1
				break
	if cnt_boys == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if not girls[i]:
				print(i, end=' ')
				break
		for i in range(1, n + 1):
			if not boys[i]:
				print(i)
				break


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	set1 = set(range(1, n + 1))
	storelist = []
	for j in range(n):
		values = list(map(int, input().split()))
		counter = 0
		if len(values) == 0:
			storelist.append(j)
		else:
			for k in range(1, values[0] + 1):
				if values[k] in set1:
					set1.remove(values[k])
					break
				else:
					counter += 1
			if counter == len(values) - 1:
				storelist.append(j)
	if len(storelist) == 0:
		print('OPTIMAL')
	else:
		random = list(set1)[0]
		print('IMPROVE')
		print(str(storelist[0] + 1) + ' ' + str(random))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()
for case in range(int(input())):
	n = int(input())
	final_set = set()
	possiblites = []
	princes_possible = [-1] * (n + 1)
	princess_possible = [False] * (n + 1)
	n_flag = False
	for i in range(n):
		temp = [int(x) for x in input().split()]
		k = temp[0]
		princes = temp[1:]
		for x in princes:
			if princes_possible[x] == -1:
				princes_possible[x] = i + 1
				princess_possible[i + 1] = True
				break
	princess = -1
	for i in range(1, n + 1):
		if princess_possible[i] == False:
			princess = i
			break
	if princess == -1:
		print('OPTIMAL')
	else:
		prince = -1
		for i in range(1, n + 1):
			if princes_possible[i] == -1:
				prince = i
				break
		print('IMPROVE')
		print(princess, prince)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	k = int(input())
	g = [[int(x) for x in input().split()[1:][::-1]] for _ in range(k)]
	a1 = set([int(x) for x in range(1, k + 1)])
	a2 = set()
	b1 = set()
	for i in range(k):
		flag = 1
		while g[i]:
			v = g[i].pop()
			if v not in a2:
				a1.discard(v)
				a2.add(v)
				flag = 0
				break
		if flag:
			b1.add(i + 1)
	if len(b1) > 0:
		print('IMPROVE')
		print(b1.pop(), a1.pop())
	else:
		print('OPTIMAL')


t = int(input())
cases = []
for _ in range(t):
	n = int(input())
	neis = []
	for _ in range(n):
		neis.append([int(i) for i in input().split()][1:])
	cases.append(neis)
for c in cases:
	busy_man = [False for _ in range(len(c))]
	busy_woman = [False for _ in range(len(c))]
	for (idx, neis) in enumerate(c):
		for nei in neis:
			if busy_man[nei - 1]:
				continue
			else:
				busy_man[nei - 1] = True
				busy_woman[idx] = True
				break
	man = None
	woman = None
	for (idx, i) in enumerate(busy_man):
		if i is False:
			man = idx
			break
	for (idx, i) in enumerate(busy_woman):
		if i is False:
			woman = idx
			break
	if man is not None:
		print('IMPROVE')
		print('{} {}'.format(woman + 1, man + 1))
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	m = [0] * n
	for i in range(n):
		m[i] = [*map(int, input().split())][1:]
	queens = [0] * n
	kings = [0] * n
	for i in range(n):
		for j in m[i]:
			if kings[j - 1] == 0:
				kings[j - 1] = 1
				queens[i] = 1
				break
	if sum(kings) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(queens.index(0) + 1, kings.index(0) + 1)


t = int(input())
for i in range(t):
	n = int(input())
	used = [0] * (n + 1)
	x = []
	for j in range(n):
		x.append(list(map(int, input().split())))
	flag = True
	for j in range(n):
		for k in range(1, x[j][0] + 1):
			if used[x[j][k]] == 0:
				used[x[j][k]] = 1
				break
		else:
			flag = False
			ind = j + 1
	if flag:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		j = 1
		while j < len(used) and used[j] == 1:
			j += 1
		print(ind, j)


for _ in range(int(input())):
	n = int(input())
	l = []
	t1 = 1
	c = 1
	s = set()
	s1 = set([i + 1 for i in range(n)])
	for i in range(n):
		l = list(map(int, input().split()))
		if l == [0]:
			l.append(0)
			t1 = 0
			ijkl = i + 1
		f = 0
		for j in range(1, l[0] + 1):
			if l[j] not in s:
				s.add(l[j])
				s1.remove(l[j])
				f = 1
				break
		if f == 0:
			c = 0
			ijkl = i + 1
	if c == 0 or t1 == 0:
		print('IMPROVE')
		if len(s1) > 0:
			for i in s1:
				answ = i
				break
			print(ijkl, answ)
		else:
			print(ijkl, n + 1)
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	daug = [False for j in range(n + 1)]
	king = [False for k in range(n + 1)]
	ans = []
	for w in range(n):
		l = list(map(int, input().split()))
		l.pop(0)
		h = 0
		for e in range(len(l)):
			if king[l[e]] == False:
				king[l[e]] = True
				daug[w + 1] = True
				h = 1
				break
		if h == 0:
			ans.append(w + 1)
		h = 0
	hew = 0
	for re in range(1, n + 1):
		if king[re] == False:
			print('IMPROVE')
			print(ans[0], re)
			hew = 1
			break
	if hew == 0:
		print('OPTIMAL')


import sys
for _ in range(int(sys.stdin.readline().lstrip().rstrip())):
	n = int(sys.stdin.readline().lstrip().rstrip())
	arr = []
	d = {}
	king = [False for i in range(n)]
	visited = [False for i in range(n)]
	for i in range(n):
		l = list(map(int, sys.stdin.readline().lstrip().rstrip().split()))
		l = l[1:]
		arr.append(l)
	for i in range(n):
		f = 0
		for j in arr[i]:
			if king[j - 1] == False:
				d[i + 1] = j
				king[j - 1] = True
				visited[i] = True
				f = 1
				break
	if len(d) == n:
		sys.stdout.write('OPTIMAL' + '\n')
	else:
		f = 0
		for i in range(n):
			if visited[i] == False:
				p1 = i + 1
				break
		for j in range(n):
			if king[j] == False:
				p2 = j + 1
		sys.stdout.write('IMPROVE' + '\n')
		sys.stdout.write(str(p1) + ' ' + str(p2) + '\n')


for _ in range(int(input())):
	n = int(input())
	temp = [0] * (n + 1)
	idx = 0
	for i in range(n):
		flag = 0
		arr = list(map(int, input().split()))
		for j in range(1, arr[0] + 1):
			if temp[arr[j]] == 0:
				temp[arr[j]] = 1
				flag = 1
				break
		if flag == 0:
			idx = i
	(count, ele) = (0, 0)
	for k in range(1, n + 1):
		if temp[k] != 0:
			count += 1
		else:
			ele = k
			break
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(idx + 1, ele)


t = int(input())
for i in range(t):
	m = int(input())
	z = []
	king = [0] * (m + 1)
	ct = 0
	for j in range(m):
		flag = 0
		ls = list(map(int, input().split()))
		for k in range(1, ls[0] + 1):
			if king[ls[k]] == 0:
				flag = 1
				king[ls[k]] = 1
				ct = ct + 1
				break
		if flag == 0:
			z.append(j)
	if ct != m:
		print('IMPROVE')
		for op in range(1, m + 1):
			if king[op] == 0:
				print(z[0] + 1, op)
				break
	else:
		print('OPTIMAL')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	d = dict()
	lis = []
	z = 0
	egg = defaultdict(int)
	for j in range(n):
		d[j + 1] = 0
		arr = list(map(int, input().split()))
		p = -1
		h = arr[0]
		if len(arr) != 0:
			arr = arr[1:]
		r = 0
		for i in range(h):
			p = arr[i]
			if egg[p] != 1:
				d[j + 1] = 1
				z += 1
				egg[p] = 1
				r = 1
				break
			if r == 1:
				break
	if z == n:
		print('OPTIMAL')
		continue
	y = 0
	x = 0
	for i in range(n):
		if d[i + 1] == 0:
			x = i + 1
			break
	for i in range(1, n + 1):
		if egg[i] != 1:
			y = i
			break
	print('IMPROVE')
	print(x, y)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	n = ni()
	a = [nl()[1:] for _ in range(n)]
	mar = [-1] * n
	g = [False] * n
	for i in range(n):
		for x in a[i]:
			if not g[x - 1]:
				mar[i] = x
				g[x - 1] = True
				break
	if min(mar) > 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
	for i in range(n):
		if mar[i] < 0:
			for j in range(n):
				if not g[j]:
					print(i + 1, j + 1)
					return
T = ni()
for _ in range(T):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
vs = set()
for _ in range(t):
	n = int(input())
	vs = set()
	d = None
	for i in range(n):
		X = list(map(int, input().split()))
		for x in X[1:]:
			if x not in vs:
				vs.add(x)
				break
		else:
			d = i + 1
	if d == None:
		print('OPTIMAL')
		continue
	print('IMPROVE')
	for i in range(1, n + 1):
		if i not in vs:
			print(d, i)
			break


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	G = [[0]] + [list(map(int, input().split()))[1:] for i in range(n)]
	P0 = [-1] * (n + 1)
	P1 = [-1] * (n + 1)
	for i in range(1, n + 1):
		for g in G[i]:
			if P1[g] == -1:
				P0[i] = g
				P1[g] = i
				break
	ANS0 = -1
	ANS1 = -1
	for i in range(1, n + 1):
		if P0[i] == -1:
			ANS0 = i
		if P1[i] == -1:
			ANS1 = i
	if ANS0 == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ANS0, ANS1)


import sys
inp = sys.stdin.readlines()
ii = 0
out = []
t = int(inp[ii])
ii += 1
for tc in range(t):
	n = int(inp[ii])
	ii += 1
	availableprincesses = []
	princes = [False for i in range(n)]
	for princess in range(1, n + 1):
		line = [int(linething) for linething in inp[ii].split()]
		ii += 1
		wishlist = line[1:]
		matched = 0
		for match in wishlist:
			if princes[match - 1] == False:
				princes[match - 1] = True
				matched = 1
				break
		if matched == 0:
			availableprincesses.append(princess)
	if len(availableprincesses) == 0:
		print('OPTIMAL')
		continue
	else:
		print('IMPROVE')
		print(availableprincesses[0], princes.index(False) + 1)


for _ in range(int(input())):
	n = int(input())
	kings = [0] * n
	queens = [0] * n
	married = 0
	qlist = []
	for __ in range(n):
		l = list(map(int, input().split()))
		qlist.append(l)
	for i in range(n):
		for j in range(1, qlist[i][0] + 1):
			if kings[qlist[i][j] - 1] == 0:
				queens[i] = qlist[i][j]
				kings[qlist[i][j] - 1] = 1
				married += 1
				break
	if married == n:
		print('OPTIMAL')
	else:
		freequeen = queens.index(0) + 1
		freeking = kings.index(0) + 1
		print('IMPROVE')
		print(freequeen, freeking)


t = int(input())
for _ in range(t):
	n = int(input())
	vis = [0] * n
	rem = -1
	for i in range(n):
		list1 = list(map(int, input().split()))
		f = 0
		for j in range(1, list1[0] + 1):
			if vis[list1[j] - 1] == 0:
				vis[list1[j] - 1] = 1
				f = 1
				break
		if f == 0:
			rem = i
	if rem == -1:
		print('OPTIMAL')
	else:
		rem2 = -1
		for i in range(n):
			if vis[i] == 0:
				rem2 = i
				break
		print('IMPROVE')
		print(rem + 1, rem2 + 1)


n_test_cases = int(input())
for test_case in range(n_test_cases):
	n = int(input())
	(daughters, kingdoms) = ([0] * n, [0] * n)
	for i in range(n):
		for j in input().split()[1:]:
			j = int(j)
			if not daughters[i] and (not kingdoms[j - 1]):
				daughters[i] = kingdoms[j - 1] = True
				break
	try:
		a = daughters.index(0)
		b = kingdoms.index(0)
		print('IMPROVE')
		print('{} {}'.format(a + 1, b + 1))
	except:
		print('OPTIMAL')


test = int(input())
for t in range(test):
	n = int(input())
	a = [False] * n
	b = [False] * n
	arr = [[] for i in range(n)]
	for i in range(n):
		x = [int(s) - 1 for s in input().split()]
		del x[0]
		arr[i] = x
	for i in range(n):
		for j in range(len(arr[i])):
			x = arr[i][j]
			if not b[x]:
				a[i] = True
				b[x] = True
				break
	ind = -1
	for i in range(len(a)):
		if not a[i]:
			ind = i
			break
	flag = True
	if ind == -1:
		print('OPTIMAL')
		continue
	indb = -1
	for i in range(len(b)):
		if not b[i]:
			indb = i
			flag = False
			break
	if not flag:
		print('IMPROVE')
		print(ind + 1, indb + 1)


for _ in range(int(input())):
	n = int(input())
	taken = set()
	takena = [0 for i in range(n)]
	dchoice = dict()
	canbeoptim = False
	for i in range(n):
		l = list(map(int, input().split()))
		choices = set(l[1:]) - taken
		if choices != set():
			c = min(choices)
			taken.add(c)
			takena[c - 1] = 1
		else:
			dchoice = i + 1
			canbeoptim = True
	if canbeoptim:
		print('IMPROVE')
		print(dchoice, takena.index(0) + 1)
	else:
		print('OPTIMAL')


T = int(input())
for case in range(T):
	np = int(input())
	arr = [[] for i in range(np)]
	taken = set()
	totake = 0
	ptake = False
	isimprove = False
	for p in range(np):
		arr[p] = [int(x) for x in input().split(' ')][1:]
	for p in range(np):
		ptake = False
		for m in arr[p]:
			if m not in taken:
				taken.add(m)
				ptake = True
				break
		if not ptake:
			totake = p + 1
			isimprove = True
	if isimprove:
		take = 0
		for i in range(1, 1 + np):
			if i not in taken:
				take = i
				break
		print('IMPROVE')
		print(totake, take)
	else:
		print('OPTIMAL')


a = int(input())
for _ in range(a):
	z = int(input())
	arm = [True] * z
	g = 0
	v = 0
	for i in range(z):
		arw = list(map(int, input().split()))
		if arw[0] == 0:
			v = i + 1
		else:
			for h in range(1, arw[0] + 1):
				if arm[arw[h] - 1] == True:
					arm[arw[h] - 1] = False
					g = 1
					break
			if g == 1:
				g = 0
			elif h == arw[0]:
				v = i + 1
	if v != 0:
		free = arm.index(True)
		print('IMPROVE')
		print(v, free + 1)
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	d = {}
	for i in range(n):
		d[i] = [int(x) for x in input().split()][1:]
	(gr, br) = ([False] * n, [False] * n)
	for (i, j) in d.items():
		for k in j:
			if gr[k - 1] == False:
				gr[k - 1] = br[i] = True
				break
	if False in gr and False in br:
		print('IMPROVE')
		print(br.index(False) + 1, gr.index(False) + 1)
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	fk = set(range(n))
	fd = set(range(n))
	for i in range(n):
		for (j, v) in enumerate(map(int, input().split())):
			if j == 0:
				continue
			v -= 1
			if v in fk:
				fk.remove(v)
				fd.remove(i)
				break
	if fk and fd:
		print('IMPROVE')
		print(fd.pop() + 1, fk.pop() + 1)
	else:
		print('OPTIMAL')


I = input
for _ in [0] * int(I()):
	r = range(int(I()))
	s = {*r}
	for i in r:
		j = next((j for j in map(int, I().split()[1:]) if {j - 1} & s), 0)
		s -= {j - 1}
		if j < 1:
			k = i + 1
	try:
		print('IMPROVE', k, s.pop() + 1)
	except:
		print('OPTIMAL')


t = int(input())
for k in range(t):
	arr = []
	arr.append([])
	n = int(input())
	for z in range(n):
		now = list(map(int, input().split()))
		now.pop(0)
		arr.append(now)
	m = [True for i in range(n + 1)]
	w = [True for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in arr[i]:
			if m[j]:
				m[j] = False
				w[i] = False
				break
	a1 = -1
	a2 = -1
	for i in range(1, n + 1):
		if m[i]:
			a2 = i
			break
	for i in range(1, n + 1):
		if w[i]:
			a1 = i
			break
	if a1 == -1 or a2 == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(a1, a2)


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	d = [0] * (n + 2)
	f = 0
	ans = -1
	g = 0
	for k in range(0, n):
		f = 0
		a = list(map(int, input().split()))
		for i in range(1, a[0] + 1):
			if d[a[i]] == 0:
				d[a[i]] = 1
				f = 1
				break
		if f == 0 and g == 0:
			g = 1
			ans = k + 1
			ans1 = a[1:]
	g = 0
	for i in range(1, n + 1):
		if d[i] == 0:
			print('IMPROVE')
			print(ans, i)
			g = 1
			break
	if g == 0:
		print('OPTIMAL')


from pprint import pprint
q = int(input())
for _ in range(q):
	n = int(input())
	target = []
	usedg = [0] * n
	usedl = [0] * n
	for i in range(n):
		l = []
		dat = list(map(int, input().split()))
		num = dat[0]
		for j in range(1, num + 1):
			dat[j] -= 1
			if usedg[dat[j]] is 0:
				usedg[dat[j]] = 1
				usedl[i] = 1
				break
	if sum(usedg) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		(a, b) = (-1, -1)
		for i in range(n):
			if usedl[i] == 0:
				a = i + 1
			if usedg[i] == 0:
				b = i + 1
		print(a, b)


t = int(input())
for i in range(t):
	l = []
	n = int(input())
	for j in range(n):
		g = list(map(int, input().split()))
		l.append(g[1:])
	x = set([])
	not_choosen_index = -1
	for kk in range(len(l)):
		k = l[kk]
		z = 0
		while z < len(k):
			if k[z] not in x:
				break
			z += 1
		if z == len(k):
			not_choosen_index = kk
			continue
		else:
			x.add(k[z])
	if len(x) != len(l):
		print('IMPROVE')
		oo = set(range(1, len(l) + 1)) - x
		print(str(not_choosen_index + 1) + ' ' + str(oo.pop()))
	else:
		print('OPTIMAL')


t = int(input(''))
while t > 0:
	s = 'OPTIMAL'
	index = 0
	d = set()
	n = int(input(''))
	for i in range(0, n):
		l = list(map(int, input().split()))
		l1 = l[1:len(l)]
		for j in l1:
			if j not in d:
				d.add(j)
				break
		else:
			index = i + 1
	if index == 0:
		print(s)
	else:
		for i in range(1, n + 1):
			if i not in d:
				print('IMPROVE')
				print(index, i)
				break
	t = t - 1


import sys
t = int(input())
g = sys.stdin.readlines()
y = 0
for t in range(t):
	n = int(g[y])
	y += 1
	count = 0
	link = [-1] * n
	x = -1
	used = [False] * n
	for i in range(n):
		a = list(map(int, g[y].split()))
		y += 1
		k = a[0]
		a = a[1:]
		j = 0
		while j < len(a) and used[a[j] - 1]:
			j += 1
		if j < len(a):
			count += 1
			link[i] = a[j] - 1
			used[a[j] - 1] = True
		else:
			x = i
	if x == -1:
		print('OPTIMAL')
	else:
		j = 0
		while j < n and used[j] == True:
			j += 1
		print('IMPROVE')
		print(x + 1, j + 1)


from sys import stdin, stdout

def solve():
	n = int(stdin.readline())
	free_princess = None
	free_princes = [True for i in range(n)]
	for i in range(n):
		for wanted_prince in map(int, stdin.readline().split()[1:]):
			if free_princes[wanted_prince - 1]:
				free_princes[wanted_prince - 1] = False
				break
		else:
			free_princess = i + 1
	if not free_princess:
		return None
	else:
		free_prince = free_princes.index(True) + 1
		return (free_princess, free_prince)
for i in range(int(stdin.readline())):
	result = solve()
	if result:
		print('IMPROVE')
		print(*result)
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	princess = []
	prince = [-1]
	for i in range(n):
		princess.append(list(map(int, input().split())))
		prince.append(-1)
	improve = 0
	for i in range(n):
		flag = 'yo'
		for j in range(1, princess[i][0] + 1):
			if prince[princess[i][j]] == -1:
				prince[princess[i][j]] = 1
				flag = 'okay'
				break
		if flag == 'yo':
			improve = i + 1
	flag = ''
	if improve != 0:
		for i in range(1, len(prince)):
			if prince[i] == -1:
				print('IMPROVE')
				print(improve, i)
				flag = 'done'
				break
		if flag == '':
			print('OPTIMAL')
	else:
		print('OPTIMAL')


for t in range(int(input())):
	a = []
	k = []
	n = int(input())
	for i in range(n):
		l = list(map(int, input().split()))
		x = []
		k.append(l[0])
		for j in range(1, l[0] + 1):
			x.append(l[j])
		a.append(x)
	p = []
	d = []
	for i in range(n):
		p.append(0)
		d.append(0)
	for i in range(n):
		for j in range(k[i]):
			if p[a[i][j] - 1] == 0:
				p[a[i][j] - 1] = 1
				d[i] = 1
				break
	ed = 0
	ep = 0
	for i in range(n):
		if d[i] == 0:
			ed = i + 1
		if p[i] == 0:
			ep = i + 1
	if ed == 0 and ep == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ed, ep)


from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil
from sys import stdin, stdout

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

def iint():
	return int(stdin.readline().strip())

def istr():
	return stdin.readline().strip()

def solve(g):
	n = len(g)
	boy = [0] * (n + 1)
	girl = [0] * (n + 1)
	for i in range(n):
		for p in g[i]:
			if not boy[p]:
				boy[p] = 1
				girl[i + 1] = 1
				break
	if sum(boy) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		(p, g) = (-1, -1)
		for i in range(1, n + 1):
			if girl[i] == 0:
				g = i
				break
		for i in range(1, n + 1):
			if boy[i] == 0:
				b = i
				break
		print(g, b)
t = iint()
for _ in range(t):
	n = iint()
	g = []
	for __ in range(n):
		g.append(ilist()[1:])
	solve(g)


for _ in range(int(input())):
	n = int(input())
	free = set(range(1, n + 1))
	unmarried = []
	for princess in range(1, n + 1):
		(_, *princes) = map(int, input().split())
		for prince in princes:
			if prince in free:
				free.remove(prince)
				break
		else:
			unmarried.append(princess)
	if unmarried:
		print('IMPROVE')
		print(unmarried[0], free.pop())
	else:
		print('OPTIMAL')


cases = int(input())
for i in range(cases):
	n = int(input())
	se = set()
	for j in range(n):
		se.add(j + 1)
	improved = False
	improvedPrincess = -1
	for princess in range(n):
		order = input()
		order = order[order.find(' ') + 1:]
		order = [int(s) for s in order.split(' ')]
		sat = False
		for prince in order:
			if prince in se:
				se.remove(prince)
				sat = True
				break
		if not sat and improved == False:
			improved = True
			improvedPrincess = princess + 1
	if not improved:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		leftover = se.pop()
		print(str(improvedPrincess) + ' ' + str(leftover))


for _ in range(int(input())):
	n = int(input())
	king = [[0]]
	for i in range(n):
		arr = list(map(int, input().split()))
		king.append(arr[1:])
	temp = [0] * (n + 1)
	idx = 0
	for i in range(1, n + 1):
		flag = 0
		for j in range(len(king[i])):
			if temp[king[i][j]] == 0:
				temp[king[i][j]] = 1
				flag = 1
				break
		if flag == 0:
			idx = i
	if temp[1:] == [1] * n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if temp[i] == 0:
				print(idx, i)
				break


for _ in range(int(input())):
	n = int(input())
	arr = [0] * (n + 1)
	hehe = []
	ans = [-1, -1]
	ok = [0] * (n + 1)
	for i in range(n):
		hehe.append(list(map(int, input().split())))
	for i in range(n):
		if hehe[i][0] != 0:
			for j in range(1, len(hehe[i])):
				if arr[hehe[i][j]] == 0:
					arr[hehe[i][j]] = 1
					ok[i + 1] = 1
					break
	for i in range(1, n + 1):
		if ok[i] == 0:
			for j in range(1, n + 1):
				if arr[j] == 0:
					ans = [i, j]
					break
			break
	if ans[0] == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ans[0], ans[1])


t = int(input())
for i in range(t):
	n = int(input())
	D = [False] * n
	K = [False] * n
	for j in range(n):
		L = list(map(int, input().split()))
		if len(L) > 1:
			for k in range(1, len(L)):
				if not K[L[k] - 1]:
					K[L[k] - 1] = True
					D[j] = True
					break
	a = -1
	b = -1
	for j in range(n):
		if not D[j] and a == -1:
			a = j + 1
		if not K[j] and b == -1:
			b = j + 1
	if a == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(a, b)


def main():
	T = int(input())
	while T > 0:
		n = int(input())
		total = set(range(1, n + 1))
		defect = []
		count = 0
		for i in range(n):
			l = input().split()
			k = int(l[0])
			l.pop(0)
			flag = True
			if k == 0:
				defect.append(i + 1)
				continue
			while k > 0 and flag:
				temp = int(l[0])
				if temp in total:
					total.remove(temp)
					flag = False
				elif len(l) != 1:
					l.pop(0)
				else:
					defect.append(i + 1)
					break
		if len(total) == 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(defect[0], ' ', total.pop())
		T -= 1
main()


from math import *
from bisect import bisect_left, bisect_right
from sys import stdin, stdout, setrecursionlimit
from collections import Counter
input = lambda : stdin.readline().strip()
print = stdout.write
t = int(input())
for _ in range(t):
	n = int(input())
	ls = []
	princesses = []
	princes = []
	for i in range(n):
		temp = list(map(int, input().split()))[1:]
		ls.append(temp)
		princesses.append(False)
		princes.append(False)
	for i in range(n):
		for j in ls[i]:
			if not princes[j - 1]:
				princes[j - 1] = True
				princesses[i] = True
				break
	princess = -1
	prince = -1
	for i in range(n):
		if not princes[i]:
			prince = i
		if not princesses[i]:
			princess = i
	if princess != -1:
		print('IMPROVE\n')
		print(str(princess + 1) + ' ' + str(prince + 1) + '\n')
	else:
		print('OPTIMAL\n')


t = int(input())
while t > 0:
	n = int(input())
	a = []
	c = []
	for i in range(n):
		c.append(0)
	for i in range(n):
		temp = [int(x) for x in input().split()]
		a.append(temp)
	l = -1
	for i in range(n):
		flag = 0
		for j in range(1, a[i][0] + 1):
			if c[a[i][j] - 1] == 0:
				c[a[i][j] - 1] = 1
				flag = 1
				break
		if flag == 0:
			l = i + 1
	if l == -1:
		print('OPTIMAL')
	else:
		for i in range(n):
			if c[i] == 0:
				print('IMPROVE')
				print(l, i + 1)
				break
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	pr = set([x for x in range(1, n + 1)])
	dt = None
	for i in range(1, n + 1):
		avail = [int(x) for x in input().split()]
		k = avail[0]
		flag = 0
		for j in range(1, k + 1):
			p = avail[j]
			if p in pr:
				pr.remove(p)
				flag = 1
				break
		if not flag:
			dt = i
	if dt:
		print('IMPROVE')
		print(dt, pr.pop())
	else:
		print('OPTIMAL')


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	d = defaultdict(list)
	for i in range(1, n + 1):
		a = [int(j) for j in input().split()]
		a = a[1:]
		a = a[::-1]
		d[i] = a
	princes = set([i for i in range(1, n + 1)])
	single = set([i for i in range(1, n + 1)])
	for i in range(1, n + 1):
		while d[i]:
			if d[i][-1] in princes:
				p = d[i].pop()
				princes.remove(p)
				single.remove(i)
				break
			else:
				d[i].pop()
	if princes:
		print('IMPROVE')
		print(single.pop(), princes.pop())
	else:
		print('OPTIMAL')


q = int(input())
for i in range(q):
	n = int(input())
	prince = set([])
	princess = set([])
	notprincess = set([])
	allprince = set([])
	notprice = set([])
	for j in range(n):
		allprince.add(j + 1)
		l = list(map(int, input().split()))
		a = True
		for k in range(l[0]):
			if l[k + 1] not in prince:
				prince.add(l[k + 1])
				a = False
				princess.add(j + 1)
				break
		if a == True:
			notprincess.add(j + 1)
	notprince = allprince.difference(prince)
	if not notprincess:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(str(notprincess.pop()) + ' ' + str(notprince.pop()))


t = int(input())
for x in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		arr.append([int(i) for i in input().split()][1:])
	st = set()
	unmarr = None
	for prin in range(len(arr)):
		for i in arr[prin]:
			if i not in st:
				st.add(i)
				break
		else:
			unmarr = prin
			continue
	if unmarr == None:
		print('OPTIMAL')
	else:
		ans = list(set(range(1, n + 1)) - st)[0]
		print('IMPROVE')
		print(unmarr + 1, ans)


t = int(input())
for i in range(t):
	n = int(input())
	L1 = [0] * n
	L2 = [0] * n
	for i in range(n):
		ch = input()
		L = [int(i) for i in ch.split()]
		x = L[0]
		for j in range(1, x + 1):
			if L2[L[j] - 1] == 0:
				L1[i] = 1
				L2[L[j] - 1] = 1
				break
	if 0 in L1 and 0 in L2:
		print('IMPROVE')
		indf = -1
		indk = -1
		for q in range(n):
			if L1[q] == 0:
				indf = q
			if L2[q] == 0:
				indk = q
		print(indf + 1, indk + 1)
		w = 1
	else:
		print('OPTIMAL')


t = int(input())
for j in range(t):
	n = int(input())
	taken_prince = [False for i in range(n)]
	taken_princess = [False for i in range(n)]
	for x in range(n):
		wanted_prince_list = list(map(int, input().split()))
		for i in wanted_prince_list[1:]:
			if taken_prince[i - 1] == False:
				taken_prince[i - 1] = True
				taken_princess[x] = True
				break
	toprint = 'OPTIMAL'
	for i in range(n):
		if taken_princess[i] == False:
			u = taken_prince.index(False)
			toprint = 'IMPROVE\n' + str(i + 1) + ' ' + str(u + 1)
			break
	print(toprint)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	n = int(input())
	l = []
	for j in range(n):
		l.append(list(map(int, input().split())))
		t = l[j][0]
		l[j] = l[j][1:]
	d = set()
	m = 0
	n1 = 0
	for j in range(n):
		x = 0
		while x < len(l[j]):
			if l[j][x] not in d:
				d.add(l[j][x])
				break
			x += 1
		if x == len(l[j]):
			m = j + 1
	for j in range(n):
		if j + 1 not in d:
			n1 = j + 1
			break
	if m == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(m, n1)


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		x = list(map(int, input().split()))
		l.append(x[1:])
	p = [0] * n
	q = [0] * n
	for i in range(n):
		for j in l[i]:
			if p[j - 1] == 0:
				p[j - 1] = 1
				q[i] = 1
				break
	f = 0
	if 0 in q:
		a = q.index(0)
		b = p.index(0)
		f = 1
	if f:
		print('IMPROVE')
		print(a + 1, b + 1)
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	kk = [0] * n
	pp = [0] * n
	for i in range(n):
		l = list(map(int, input().split()))
		for j in range(1, l[0] + 1):
			jj = l[j] - 1
			if kk[jj] == 0:
				kk[jj] = pp[i] = 1
				break
	kkk = ppp = 0
	for i in range(n):
		if kk[i] == 0:
			kkk = i + 1
		if pp[i] == 0:
			ppp = i + 1
	if kkk and ppp:
		print('IMPROVE')
		print(ppp, kkk)
	else:
		print('OPTIMAL')


for tc in range(int(input())):
	n = int(input())
	g = [set() for i in range(n)]
	vis = set()
	ans = [0] * n
	anss = set(range(1, n + 1))
	for t in range(n):
		q = list(map(int, input().split()))
		q = set(q[1:])
		try:
			q = min(q - vis)
			vis.add(q)
			ans[t] = q
		except:
			continue
	if ans.count(0) == 0:
		print('OPTIMAL')
	elif ans.count(0) >= 1:
		print('IMPROVE')
		h = min(anss - vis)
		print(ans.index(0) + 1, h)


for _ in range(int(input())):
	n = int(input())
	d = {}
	fd = set()
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		l.pop(0)
		d[i] = l
		fd.add(i)
	i = 0
	s = []
	for i in range(1, n + 1):
		r = d[i]
		f = 1
		while len(r) != 0 and f == 1:
			x = r.pop(0)
			if x in fd:
				fd.remove(x)
				f = 0
		if f == 1:
			s.append(i)
	g = 0
	ll = list(fd)
	if len(s) == 0 or len(ll) == 0:
		print('OPTIMAL')
	else:
		x = s.pop(0)
		print('IMPROVE')
		print(x, ll[0])


t_cases = int(input())
for i in range(t_cases):
	n_daughters = int(input())
	list_daughters = []
	for j in range(n_daughters):
		list_daughters.append(list(map(int, input().split())))
	kingdoms = [0] * n_daughters
	i = 0
	lost_daughter = -1
	lost_kingdom = -1
	while i < n_daughters:
		marry = False
		if list_daughters[i][0] > 0:
			index = 1
			while index <= list_daughters[i][0]:
				if kingdoms[list_daughters[i][index] - 1] == 0:
					marry = True
					kingdoms[list_daughters[i][index] - 1] = 1
					break
				index += 1
		if not marry and lost_daughter == -1:
			lost_daughter = i
		i += 1
	for (j, princes) in enumerate(kingdoms):
		if princes == 0:
			lost_kingdom = j
			break
	if lost_daughter == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(lost_daughter + 1, lost_kingdom + 1)


t = int(input())
for p in range(0, t):
	n = int(input())
	v = [0]
	for i in range(0, n):
		a = list(map(int, input().split()))
		if a[0] == 0:
			v.append([])
		else:
			v.append(a[1:])
	visited = [0] * (n + 1)
	married = [0] * (n + 1)
	for i in range(1, n + 1):
		for j in v[i]:
			if visited[j] == 0:
				visited[j] = 1
				married[i] = 1
				break
	if visited.count(1) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(married[1:].index(0) + 1, end=' ')
		print(visited[1:].index(0) + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	taken = [0] * (n + 1)
	t = 0
	di = {}
	d2 = {}
	ans = []
	for fu in range(n):
		a = sorted(list(map(int, input().split()))[1:])
		married = False
		for each in a:
			if taken[each] == 0:
				taken[each] = 1
				married = True
				break
		if not married:
			ans += [fu + 1]
	if len(ans) > 0:
		print('IMPROVE')
		ans2 = 1
		for i in range(1, n + 1):
			if taken[i] == 0:
				ans2 = i
				break
		print(ans[0], ans2)
	else:
		print('OPTIMAL')


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def simulate(n, lists):
	seen_kingdoms = [False for i in range(n)]
	seen_princesses = [False for i in range(n)]
	for i in range(n):
		cur = lists[i]
		length = cur[0]
		for j in range(1, length + 1):
			if not seen_kingdoms[cur[j] - 1]:
				seen_kingdoms[cur[j] - 1] = True
				seen_princesses[i] = True
				break
	x = -1
	y = -1
	for i in range(n):
		if not seen_kingdoms[i]:
			y = i + 1
			break
	for i in range(n):
		if not seen_princesses[i]:
			x = i + 1
			break
	return (x, y)
testcases = int(input())
for case in range(testcases):
	n = int(input())
	lists = []
	for i in range(n):
		l = [int(zax) for zax in input().split()]
		lists.append(l)
	(x, y) = simulate(n, lists)
	if x == -1 and y == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print('{} {}'.format(x, y))


t = int(input())
for _ in range(t):
	n = int(input())
	s = set(range(1, n + 1))
	l = []
	for i in range(n):
		k = list(map(int, input().split()))
		k = set(k[1:])
		k = k.intersection(s)
		if len(k) == 0:
			l.append(-1)
		else:
			l.append(min(k))
			s.remove(min(k))
	if len(s) == 0:
		print('OPTIMAL')
	else:
		for i in range(n):
			if l[i] == -1 and len(s) != 0:
				print('IMPROVE')
				print(i + 1, min(s), ' ')
				break
			else:
				continue
		else:
			print('OPTIMAL')


list_ans = []
for _ in range(int(input())):
	n = int(input())
	list1 = []
	set1 = set()
	for i in range(n):
		(a, *listx) = map(int, input().split())
		for x in listx:
			if x not in set1:
				set1.add(x)
				break
		else:
			list1.append(i + 1)
	if len(list1) == 0:
		list_ans.append('OPTIMAL')
	else:
		list_ans.append('IMPROVE')
		a = list1[0]
		for x in range(1, n + 1):
			if x not in set1:
				break
		list_ans.append(' '.join([str(a), str(x)]))
for item in list_ans:
	print(item)


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
t = inn()
for tt in range(t):
	n = inn()
	a = []
	for i in range(n):
		x = inl()
		a.append(x[1:])
	e = [-1] * n
	sbad = []
	for i in range(n):
		s = -1
		for j in a[i]:
			if e[j - 1] < 0:
				s = j - 1
				e[j - 1] = i
				break
		if s < 0:
			sbad.append(i)
	if len(sbad) == 0:
		print('OPTIMAL')
		continue
	i1 = sbad[0]
	for j in range(n):
		if e[j] < 0:
			print('IMPROVE')
			print('{} {}'.format(i1 + 1, j + 1))
			break


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from math import sqrt, floor, factorial, gcd
from collections import deque, Counter, defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from collections import deque
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		n = int(input())
		not_visited = {i + 1 for i in range(n)}
		no_match = []
		for i in range(n):
			arr = read()
			flag = 0
			for j in range(1, arr[0] + 1):
				if arr[j] in not_visited:
					not_visited.remove(arr[j])
					flag = 1
					break
			if not flag:
				no_match.append(i + 1)
		not_visited = list(not_visited)
		if no_match and not_visited:
			print('IMPROVE')
			print(no_match[0], not_visited[0])
		else:
			print('OPTIMAL')
solve()


t = int(input())
for i in range(t):
	nod = int(input())
	l = []
	for j in range(nod):
		l.append(list(map(int, input().strip().split())))
	kingdom = [0] * nod
	unmarried = -1
	for j in range(nod):
		flag = 0
		for k in range(l[j][0]):
			if kingdom[l[j][k + 1] - 1] != 1:
				kingdom[l[j][k + 1] - 1] = 1
				flag = 1
				break
		if flag == 0 and unmarried == -1:
			unmarried = j + 1
	if unmarried == -1:
		print('OPTIMAL')
	else:
		ans = 0
		for j in range(nod):
			if kingdom[j] == 0:
				ans = j + 1
				break
		if ans == 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(unmarried, ans)


class daughter:

	def __init__(self, number, princes):
		self.prince_wishlist = sorted(princes)
		self.number_of_princes = number
		self.matched = False
		self.number_matched_prince = 0

	def match_prince(self, prince):
		self.number_matched_prince = prince
		self.matched = True

def match(daughter, princes):
	for i in range(0, daughter.number_of_princes):
		if princes[daughter.prince_wishlist[i] - 1] == 1:
			princes[daughter.prince_wishlist[i] - 1] = 0
			daughter.match_prince(daughter.prince_wishlist[i])
			break
	return princes
tc = int(input())
while tc > 0:
	n = int(input())
	list_of_daughters = [None] * n
	list_of_princes = [1] * n
	match_counter = 0
	no_improve = True
	for i in range(0, n):
		temp_list = list(map(int, input().split()))
		list_of_daughters[i] = daughter(temp_list[0], temp_list[1:])
	for d in list_of_daughters:
		list_of_princes = match(d, list_of_princes)
		if d.matched:
			match_counter += 1
	if match_counter == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for d in range(0, n):
			if no_improve:
				if list_of_daughters[d].matched == False:
					for p in range(0, len(list_of_princes)):
						if list_of_princes[p] == 1:
							print(f'{d + 1} {p + 1}')
							no_improve = False
							break
	tc -= 1


answer = ''
T = int(input())
for t in range(T):
	n = int(input())
	boys = [False for i in range(n)]
	girs = []
	for i in range(n):
		new = list(map(int, input().split()))
		if new == [0]:
			girs.append(i + 1)
		else:
			ok = False
			for j in range(new[0]):
				ind = new[j + 1] - 1
				if boys[ind] == False:
					boys[ind] = True
					ok = True
					break
			if not ok:
				girs.append(i + 1)
	if girs == []:
		answer += 'OPTIMAL\n'
	else:
		for i in range(n):
			if boys[i] == False:
				boy = i + 1
				break
		answer += 'IMPROVE\n'
		answer += str(girs[0]) + ' ' + str(boy) + '\n'
print(answer)


t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	for j in range(n):
		a1 = input().split(' ')
		arr.append([])
		for c in range(len(a1)):
			arr[j].append(int(a1[c]))
	done = set()
	remain = []
	count = 0
	for k in range(len(arr)):
		p = arr[k]
		flag = 0
		for q in range(1, len(p)):
			if p[q] not in done:
				done.add(p[q])
				flag = 1
				count += 1
				break
		if flag == 0:
			p.append(k)
			remain.append(p)
	if count == n:
		print('OPTIMAL')
		continue
	prince = list(done)
	prince.sort()
	num = -1
	for w in range(len(prince) - 1):
		if prince[w] != prince[w + 1] - 1:
			num = prince[w] + 1
			break
	if num == -1:
		if len(prince) > 0 and prince[0] >= 2:
			num = 1
		else:
			num = len(prince) + 1
	add = -1
	for z in range(len(remain)):
		element = remain[z]
		if num not in element[1:len(element) - 1]:
			add = element[len(element) - 1]
			break
	print('IMPROVE')
	print(str(add + 1), num)


t = int(input())
for k in range(t):
	n = int(input())
	isset = [0] * n
	last = -1
	for i in range(n):
		a = input().split()
		deff = 0
		for j in range(1, min(i + 2, int(a[0]) + 1)):
			if isset[int(a[j]) - 1] == 0:
				isset[int(a[j]) - 1] = int(a[j])
				deff = 1
				break
		if deff == 0:
			last = i + 1
	if last != -1:
		print('IMPROVE')
		for i in range(n):
			if isset[i] == 0:
				print(last, i + 1)
				break
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	ar = [False for i in range(n)]
	fl = [False for i in range(n)]
	d = {}
	for i in range(n):
		l = list(map(int, input().split()))
		mr = l[1:]
		if l[0] == 0:
			continue
		for j in mr:
			if ar[j - 1] == False:
				ar[j - 1] = True
				fl[i] = True
				break
	if fl.count(False) > 0:
		print('IMPROVE')
		ind = fl.index(False)
		rev = ar[::-1].index(False)
		print(ind + 1, n - rev)
	else:
		print('OPTIMAL')


x = int(input())
for _ in range(x):
	y = int(input())
	prince = [0] * y
	count = 0
	thing = 0
	for q in range(y):
		data = list(map(int, input().split()))
		data.pop(0)
		flag = False
		for i in range(len(data)):
			if prince[data[i] - 1] == 0 and data[i] > 0:
				prince[data[i] - 1] = 1
				flag = True
				break
		if thing == 0 and flag == False:
			count = q + 1
			thing += 1
	if count > 0:
		for i in range(len(prince)):
			if prince[i] == 0:
				print('IMPROVE')
				print('{} {}'.format(count, i + 1))
				break
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	d = [0] * n
	c1 = 0
	l3 = []
	for i in range(n):
		flag = 0
		l1 = list(map(int, input().split()))
		k = l1.pop(0)
		for j in range(k):
			if d[l1[j] - 1] == 0:
				d[l1[j] - 1] = 1
				flag = 1
				break
		if flag == 0:
			l3.append(i)
	if len(l3) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(l3[0] + 1, end=' ')
		for i in range(n):
			if d[i] == 0:
				print(i + 1)
				break


def solve():
	n = int(input())
	prin = []
	mk = [False] * n
	mp = [False] * n
	for i in range(n):
		aux = list(map(int, input().split()))[1:]
		prin.append(aux)
	improve = None
	for i in range(1, n + 1):
		p = prin[i - 1]
		for j in p:
			if not mk[j - 1]:
				mk[j - 1] = True
				mp[i - 1] = True
				break
	for i in range(1, n + 1):
		if not mp[i - 1]:
			for j in range(1, n + 1):
				if not mk[j - 1]:
					improve = (i, j)
					break
		if improve is not None:
			break
	if improve is None:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		(p, k) = improve
		print(p, k)

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


from sys import stdin, stdout
t = int(stdin.readline())
while t:
	n = int(stdin.readline())
	used = set()
	total = set()
	alone = 0
	for i in range(1, n + 1):
		marr = 0
		(k, *l) = map(int, stdin.readline().split(' '))
		total.update(l)
		for p in l:
			if p not in used:
				used.add(p)
				marr = p
				break
		if alone == 0 and marr == 0:
			alone = i
	if alone == 0:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		rem = total - used
		if rem:
			kingd = next(iter(rem))
			stdout.write(str(alone) + ' ' + str(kingd) + '\n')
		else:
			new_king = 0
			for kk in range(1, n + 1):
				if kk not in used:
					new_king = kk
					break
			if new_king == 0 or new_king > n:
				stdout.write('OPTIMAL\n')
			else:
				stdout.write(str(alone) + ' ' + str(new_king) + '\n')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	d = {}
	l = {i: 1 for i in range(1, n + 1)}
	res = []
	count = 0
	pos = 0
	for j in range(n):
		k = list(map(int, input().split()))
		k = sorted(set(k[1:]))
		if len(k) > 0 and k[0] != 0:
			f = 0
			for j1 in k:
				if j1 not in d:
					d[j1] = 1
					if j1 in l:
						del l[j1]
					f = 1
					break
			if f == 0:
				count = 1
				if pos == 0:
					pos = j + 1
		else:
			count = 1
			if pos == 0:
				pos = j + 1
	h = 0
	for i in l:
		h = i
		break
	if len(l) > 0 and count > 0:
		print('IMPROVE')
		print(pos, h)
	else:
		print('OPTIMAL')


o = int(input())
for i in range(o):
	a = int(input())
	son = [0 for i in range(a)]
	dau = [0 for i in range(a)]
	ans = []
	for i in range(a):
		z = list(map(int, input().split()))
		z = z[1:]
		ans.append(z)
	for i in range(len(ans)):
		for j in range(len(ans[i])):
			if son[ans[i][j] - 1] == 0:
				son[ans[i][j] - 1] = 1
				dau[i] = 1
				break
	flag = 0
	save = 0
	for i in range(len(son)):
		if son[i] == 0:
			save = i
			flag = 1
			break
	if flag == 1:
		for i in range(len(dau)):
			if dau[i] == 0:
				print('IMPROVE')
				print(i + 1, save + 1)
				break
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	l = [False] * n
	arr = []
	free = []
	for a in range(n):
		x = list(map(int, input().split()))
		arr.append(x)
		for i in x[1:]:
			if l[i - 1] == False:
				l[i - 1] = True
				break
		else:
			free.append(a)
	if all(l):
		print('OPTIMAL')
	else:
		printed = False
		for i in range(n):
			if printed:
				break
			if not l[i]:
				for x in free:
					if i + 1 not in arr[x][1:]:
						print('IMPROVE')
						print(x + 1, i + 1)
						printed = True
					if printed:
						break
		if not printed:
			print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	done = set()
	fav = []
	left = []
	for __ in range(n):
		(k, *f) = map(int, input().split())
		fav.append(f)
	for i in range(n):
		for j in range(len(fav[i])):
			if fav[i][j] in done:
				None
			else:
				done.add(fav[i][j])
				break
		else:
			left.append(i + 1)
	pr = set()
	for i in range(n):
		pr.add(i + 1)
	prleft = pr.difference(done)
	if len(prleft) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(left[0], prleft.pop())


def main():
	result = str()
	for _ in range(int(input())):
		n = int(input())
		freeDaughter = 0
		freeKingdoms = [0] * n
		for i in range(n):
			for j in list(map(int, input().split()))[1:]:
				if freeKingdoms[j - 1]:
					continue
				freeKingdoms[j - 1] = 1
				break
			else:
				if freeDaughter == 0:
					freeDaughter = i + 1
		if freeDaughter:
			if 0 in freeKingdoms:
				result += f'IMPROVE\n{freeDaughter} {freeKingdoms.index(0) + 1}\n'
			else:
				result += f'IMPROVE\n{freeDaughter} 1\n'
		else:
			result += 'OPTIMAL\n'
	print(result)
main()


test_cases = int(input())
for i in range(test_cases):
	married = {}
	kingdoms = int(input())
	daughter_not_married = -1
	for daughter in range(1, kingdoms + 1):
		line = input()
		line = line.split()
		entries = int(line[0])
		is_married = False
		for pref in range(entries):
			a_pref = int(line[pref + 1])
			if married.get(a_pref, None) is None:
				married[a_pref] = 1
				is_married = True
				break
		if not is_married:
			daughter_not_married = daughter
	can_improve = False
	if daughter_not_married != -1:
		for kingdom in range(1, kingdoms + 1):
			if married.get(kingdom, None) is None:
				print('IMPROVE')
				print(str(daughter_not_married) + ' ' + str(kingdom))
				can_improve = True
				break
	if not can_improve:
		print('OPTIMAL')


t = int(input())
while t:
	n = int(input())
	d = []
	N = n
	while n:
		k = [int(x) for x in input().split()]
		p = k[1:]
		d.append(p)
		n -= 1
	done = {int(x) for x in range(1, N + 1)}
	incomplete = []
	i = 1
	for list in d:
		inc = True
		for x in list:
			if x in done:
				done.remove(x)
				inc = False
				break
		if inc:
			incomplete.append(i)
		i += 1
	if len(incomplete) != 0:
		print('IMPROVE')
		for e in done:
			break
		print(str(incomplete[0]) + ' ' + str(e))
	else:
		print('OPTIMAL')
	t -= 1


for t in range(int(input())):
	n = int(input())
	visited = [False] * n
	single = []
	for N in range(n):
		arr = list(map(int, input().split()))
		max_n = arr.pop(0)
		flag = False
		i = 0
		while i < max_n:
			if not visited[arr[i] - 1]:
				visited[arr[i] - 1] = True
				flag = True
				break
			i += 1
		if not flag:
			single.append(N)
	if single == []:
		print('OPTIMAL')
	else:
		prince = []
		for i in range(n):
			if not visited[i]:
				prince.append(i)
		if prince == []:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			for i in range(min(len(prince), len(single))):
				print(single[i] + 1, prince[i] + 1)
				break


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	g = []
	used = set()
	x = set()
	for i in range(n):
		l = set(list(map(int, input().split()))[1:]).difference(used)
		if l:
			used.add(sorted(l)[0])
		else:
			x.add(i)
	if x:
		print('IMPROVE')
		for x in x:
			break
		for y in set(range(1, n + 1)).difference(used):
			break
		print(x + 1, y)
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	king = []
	temp = []
	for j in range(n):
		tp = list(map(int, input().split()))
		l = tp[1:]
		a.append(l)
		king.append(0)
		temp.append(0)
	for k in range(len(a)):
		for m in range(len(a[k])):
			if king[a[k][m] - 1] != 1:
				king[a[k][m] - 1] = 1
				temp[k] = 1
				break
			else:
				continue
	if 0 in king or 0 in temp:
		print('IMPROVE')
		a = temp.index(0)
		b = king.index(0)
		a = a + 1
		b = b + 1
		print(a, b)
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	x = dict()
	count = 0
	for i in range(n):
		l = list(map(int, input().split()))
		flag = 0
		for j in range(1, l[0] + 1):
			if l[j] not in x:
				x[l[j]] = 1
				count += 1
				flag = 1
				break
		if flag == 0:
			rock = i + 1
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in x:
				break
		print(rock, i)


from sys import stdin, stdout
h = int(stdin.readline())
for _ in range(h):
	k = 0
	n = int(stdin.readline())
	v = [0] * n
	for i in range(n):
		l = 0
		a = list(map(int, stdin.readline().split()))[1:][::-1]
		if a:
			for t in a:
				if not v[t - 1]:
					l = t
			if l:
				v[l - 1] = 1
			else:
				k = i + 1
		else:
			k = i + 1
	if k:
		stdout.write('IMPROVE\n')
		stdout.write(str(k) + ' ' + str(v.index(0) + 1) + '\n')
	else:
		stdout.write('OPTIMAL\n')


t = int(input())
for _ in range(t):
	n = int(input())
	g = {}
	pm = {}
	pf = {}
	for x in range(n):
		inp = input().split()
		k = int(inp[0])
		for y in range(k):
			p = int(inp[y + 1])
			try:
				temp = pm[p]
			except:
				pm[p] = 1
				pf[x + 1] = 1
				break
	flag = True
	mout = ''
	fout = ''
	for x in range(n):
		try:
			temp = pf[x + 1]
		except:
			flag = False
			cess = x + 1
			break
	if flag == False:
		for x in range(1, n + 1):
			try:
				temp = pm[x]
			except:
				ce = x
				break
		print('IMPROVE')
		print(cess, ce)
	else:
		print('OPTIMAL')


def sol(n, ps):
	found = set()
	for (i, p) in enumerate(ps, 1):
		for x in p:
			if x not in found:
				found.add(x)
				break
		else:
			fi = i
	if len(found) == n:
		return
	return (fi, next(iter(set(range(1, n + 1)) - found)))
for _ in range(int(input())):
	n = int(input())
	ps = [list(map(int, input().split()))[1:] for _ in range(n)]
	ans = sol(n, ps)
	if ans:
		print('IMPROVE')
		print(' '.join(map(str, ans)))
	else:
		print('OPTIMAL')


from sys import stdout, stdin
t = int(stdin.readline())
for tt in range(t):
	n = int(stdin.readline())
	prince = [False for i in range(n)]
	d = -1
	for i in range(n):
		a = [int(x) - 1 for x in stdin.readline().split()][1:]
		for j in a:
			if not prince[j]:
				prince[j] = True
				break
		else:
			d = i
	if d == -1:
		stdout.write('OPTIMAL\n')
	else:
		p = prince.index(False)
		stdout.write('IMPROVE\n' + str(d + 1) + ' ' + str(p + 1) + '\n')


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq

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

def line():
	p = list(map(int, input().split()))
	return p

def check(a, b, x, y):
	if x > b:
		return 0
	if y < a:
		return 0
	return 1

def cval(s):
	return int(s, 36) - 10
for _ in range(inp()):
	n = inp()
	p = []
	q = dc(int)
	left = 0
	c = 0
	for i in range(n):
		p.append(line())
	for i in range(n):
		l = p[i]
		z = c
		for j in range(1, l[0] + 1):
			if q[l[j]] == 0:
				q[l[j]] = 1
				c += 1
				break
		if z == c and left == 0:
			left = i + 1
	if left != 0:
		print('IMPROVE')
		for k in range(1, n + 1):
			if q[k] == 0:
				print(left, k)
				break
	else:
		print('OPTIMAL')


import sys
for _ in range(int(input())):
	n = int(sys.stdin.readline())
	p = {}
	d = {}
	for i in range(1, n + 1):
		p[i] = 0
		d[i] = 0
	li = [[]]
	for i in range(n):
		li.append(list(map(int, sys.stdin.readline().split()))[1:])
	for i in range(1, n + 1):
		for j in li[i]:
			if p[j] == 0:
				p[j] = i
				d[i] = j
				break
	if min(d.values()) == 0:
		print('IMPROVE')
		for x in d:
			if d[x] == 0:
				for y in p:
					if p[y] == 0:
						print(x, y)
						break
				break
	else:
		print('OPTIMAL')


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	n = intput()
	failed = None
	occupied = set()
	for i in range(n):
		g = list(intsput())
		for j in range(1, len(g)):
			if g[j] in occupied:
				pass
			else:
				occupied.add(g[j])
				break
		else:
			failed = i + 1
	target = None
	for i in range(1, n + 1):
		if i not in occupied:
			target = i
			break
	if failed is not None:
		print('IMPROVE')
		print(failed, target)
	else:
		print('OPTIMAL')


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
import sys, bisect, string, math, time, functools, random

def Golf():
	(*a,) = map(int, open(0))

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, boundary=1, search=[], replacement_of_found='.', mp_def={'#': 1, '.': 0}):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(k, n=2):
	return [[tb // n ** bt % n for bt in range(k)] for tb in range(n ** k)]

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)

def show2d(g, h, w):
	for i in range(h):
		show(g[i * w:i * w + w])
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
t = I()
for _ in range(t):
	ans = 0
	k = I()
	l = []
	for i in range(k):
		(x, *g) = LI_()
		l += [g]

	def solve(k, g):
		p = [0] * k
		cnt = 0
		mikon = -1
		for i in range(k):
			fl = False
			for j in g[i]:
				if p[j] == 0:
					p[j] = 1
					cnt += 1
					fl = True
					break
			if fl:
				pass
			else:
				mikon = i
		if mikon == -1:
			return -1
		for j in range(k):
			if p[j] == 0:
				return (mikon + 1, j + 1)
		return p
	r = solve(k, l)
	if r == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(*r)


from sys import stdin
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	entry = []
	for i in range(n):
		entry.append(list(map(int, stdin.readline().split()))[1:])
	num = 0
	state_prince = [1 for i in range(n)]
	alone_index = -1
	for i in range(n):
		item = entry[i]
		if len(item) == 0:
			alone_index = i
			continue
		state = 0
		for prince in item:
			if state_prince[prince - 1] == 1:
				num += 1
				state_prince[prince - 1] = 0
				state = 1
				break
		if state == 0:
			alone_index = i
	if num == n:
		print('OPTIMAL')
	else:
		for i in range(n):
			if state_prince[i] == 1:
				print('IMPROVE')
				print(alone_index + 1, i + 1)
				break


from sys import stdin
from heapq import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	chk = [0] * (n + 1)
	d = [0] * (n + 1)
	s = [0] * (n + 1)
	idx = [0] * (n + 1)
	l = [[0]]
	h = []
	for x in range(1, n + 1):
		t = [int(y) for y in input().split()]
		if t[0] == 0:
			l.append([])
			continue
		now = []
		heappush(h, (t[1], x))
		for y in t[1:]:
			now.append(y)
		l.append(now)
	while True:
		if len(h) == 0:
			break
		hnow = heappop(h)
		if s[hnow[0]] == 0 and d[hnow[1]] == 0:
			s[hnow[0]] = 1
			d[hnow[1]] = 1
		elif len(l[hnow[1]]) - 1 > idx[hnow[1]]:
			idx[hnow[1]] += 1
			heappush(h, (l[hnow[1]][idx[hnow[1]]], hnow[1]))
	(dnow, snow) = (0, 0)
	for x in range(1, n + 1):
		if d[x] == 0:
			dnow = x
			break
	for x in range(1, n + 1):
		if s[x] == 0:
			snow = x
			break
	if dnow == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(dnow, snow)


def solve():
	N = int(input())
	taken = [False] * N
	princess = -1
	for i in range(N):
		x = list(map(int, input().split()))
		who = -1
		for j in range(x[0]):
			if not taken[x[j + 1] - 1]:
				who = x[j + 1] - 1
				taken[x[j + 1] - 1] = True
				break
		if who == -1:
			princess = i
	prince = -1
	for i in range(N):
		if not taken[i]:
			prince = i
			break
	if princess == -1 or prince == -1:
		print('OPTIMAL')
	else:
		princess += 1
		prince += 1
		print('IMPROVE')
		print(princess, end=' ')
		print(prince)
T = int(input())
for i in range(T):
	solve()


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

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 dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = []
			princes = {i: 1 for i in range(1, n + 1)}
			for i in range(n):
				arr = inlt()
				if arr[0] != 0:
					a.append([i, arr[1:]])
				else:
					a.append([i, []])
			idx = -1
			prince = -1
			for i in range(n):
				arr = a[i]
				for j in arr[1]:
					if j in princes:
						del princes[j]
						break
				else:
					idx = i + 1
			if princes.keys():
				prince = list(princes.keys())[0]
			if idx != -1 and prince != -1:
				print('IMPROVE')
				print(idx, prince)
			else:
				print('OPTIMAL')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	g = [list(map(int, input().split()))[1:] for i in range(n)]
	(kingdom_left, left) = (set(range(1, n + 1)), list(range(1, n + 1)))
	for _ in range(n):
		for cur in g[_]:
			if cur in kingdom_left:
				kingdom_left.remove(cur)
				break
		else:
			left.append(_ + 1)
	if len(left) and len(kingdom_left):
		print('IMPROVE\n{} {}'.format(left[-1], kingdom_left.pop()))
	else:
		print('OPTIMAL')
t = int(input())
for _ in range(t):
	solve()


m = int(input())
for l in range(m):
	n = int(input())
	d = [0 for _ in range(n)]
	l = -1
	for j in range(n):
		k = [int(x) for x in input().split(' ')]
		flag = 0
		for i in k[1:]:
			if d[i - 1] == 0:
				flag = 1
				d[i - 1] = 1
				break
		if flag == 0:
			l = j + 1
	if l != -1:
		print('IMPROVE')
		print(str(l) + ' ' + str(d.index(0) + 1))
	else:
		print('OPTIMAL')


def solve(arr, n, ans):
	edges = {}
	rem = set()
	for i in range(1, n + 1):
		edges[i] = []
		rem.add(i)
	for i in range(n):
		arr1 = arr[i]
		start = i + 1
		for j in range(1, len(arr1)):
			if arr1[j] in rem:
				edges[start].append(arr1[j])
				rem.remove(arr1[j])
				break
	incoming = set()
	for i in range(1, n + 1):
		incoming.add(i)
	not_married = []
	for i in edges.keys():
		if not edges[i]:
			not_married.append(i)
		for j in edges[i]:
			incoming.remove(j)
	if not incoming:
		ans.append('OPTIMAL')
	elif not not_married:
		ans.append('OPTIMAL')
	else:
		start = not_married.pop()
		end = incoming.pop()
		ans.append('IMPROVE')
		ans.append(str(start) + ' ' + str(end))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = []
		for j in range(n):
			arr.append(list(map(int, input().split())))
		solve(arr, n, ans)
	for i in ans:
		print(i)
main()


for _ in range(int(input())):
	n = int(input())
	graph = [[] for _ in range(n + 1)]
	for i in range(1, n + 1):
		graph[i] = list(map(int, input().split()))[1:]
	mt1 = [-1] * (n + 1)
	mt2 = [-1] * (n + 1)
	mt1[0] = mt2[0] = 10 ** 9
	bad = -1
	for i in range(1, n + 1):
		fl = False
		for to in graph[i]:
			if mt2[to] == -1:
				mt1[i] = to
				mt2[to] = i
				fl = True
				break
		if not fl:
			bad = i
	if bad != -1:
		to = mt2.index(-1)
		print('IMPROVE')
		print(bad, to)
	else:
		print('OPTIMAL')


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
for _ in range(int(input())):
	n = inn()
	d = defaultdict(int)
	res = -1
	for i in range(n):
		a = arr()
		flag = 0
		for j in range(1, a[0] + 1):
			if a[j] not in d:
				d[a[j]] -= 1
				flag = 1
				break
		if flag == 0:
			res = i + 1
	flag = 0
	val = 0
	for i in range(1, n + 1):
		if i not in d:
			val = i
			flag = 1
			break
	if res == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(res, val)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		b = [int(j) for j in input().split()]
		a.append(b[1:])
	b = []
	c = []
	for i in range(n):
		b.append(0)
		c.append(0)
	for i in range(n):
		for j in range(len(a[i])):
			if b[a[i][j] - 1] == 0:
				b[a[i][j] - 1] = 1
				c[i] = 1
				break
	if 0 in b:
		print('IMPROVE')
		print(c.index(0) + 1, b.index(0) + 1)
	else:
		print('OPTIMAL')


def solution():
	from sys import stdout, stdin
	(_input, _print) = (stdin.readline, stdout.write)
	(_list, _range, _int, _set) = (list, range, int, set)
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = [0] * n
		mariage = _set()
		dother = [False] * n
		for g in _range(n):
			arr[g] = [_int(i) for i in _input().split()]
			for i in arr[g][1:]:
				if not i in mariage:
					mariage.add(i)
					dother[g] = True
					break
		if False in dother:
			l = dother.index(False)
			not_mariage = {i for i in _range(1, n + 1)}.difference(mariage)
			print('IMPROVE')
			print(l + 1, not_mariage.pop())
		else:
			print('OPTIMAL')
solution()


for _ in range(int(input())):
	n = int(input())
	a = []
	for j in range(n):
		x = [int(i) - 1 for i in input().split()]
		x = x[1:]
		a.append(x)
	v = [0 for i in range(n)]
	ct = 0
	l = []
	for i in range(n):
		x = a[i]
		minn = 10 ** 18
		for j in x:
			if v[j] == 0:
				minn = min(minn, j)
		if minn == 10 ** 18:
			l.append(i)
		else:
			ct += 1
			v[minn] = 1
	if ct == n:
		print('OPTIMAL')
		continue
	minnn = -1
	for i in range(n):
		if v[i] == 0:
			minnn = i
			break
	if minnn != -1:
		print('IMPROVE')
		print(l[0] + 1, minnn + 1)
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	used = [False] * n
	lohi = []
	for i in range(1, n + 1):
		boo = False
		arr = list(map(int, input().split()))
		for j in range(1, len(arr)):
			if used[arr[j] - 1] == False:
				used[arr[j] - 1] = True
				boo = True
				break
		if boo == False:
			lohi.append(i)
	if len(lohi) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		r = used.index(False)
		print(f'{lohi[0]} {r + 1}')


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		tmp = list(mapi())
		a.append(tmp[1:])
	mrk = [0] * (n + 1)
	dn = [0] * (n + 1)
	for i in range(n):
		a[i].sort()
		try:
			j = 0
			while mrk[a[i][j]] and j < len(a[i]):
				j += 1
			if mrk[a[i][j]] == 0:
				mrk[a[i][j]] = 1
				dn[i + 1] = 1
		except:
			pass
	x = 0
	y = 0
	for i in range(1, len(dn)):
		if dn[i] == 0:
			x = i
			break
	for i in range(1, len(mrk)):
		if mrk[i] == 0:
			y = i
			break
	if x != 0:
		print('IMPROVE')
		print(x, y)
	else:
		print('OPTIMAL')


def main():
	for _ in range(int(input())):
		n = int(input())
		visited = [False] * n
		q = [list(map(int, input().split())) for i in range(n)]
		(t1, x) = (0, 0)
		for i in range(n):
			t = -1
			if len(q[i]) > 1:
				t = min(q[i][1:], key=lambda x: n + 1 if visited[x - 1] else x)
			elif t1 == 0 and x == 0:
				t1 = -1
				x = i
			if t != -1 and (not visited[t - 1]):
				visited[t - 1] = True
			elif t1 == 0 and x == 0:
				t1 = -1
				x = i
		if t1 == -1:
			print('IMPROVE')
			print(x + 1, visited.index(False) + 1)
		else:
			print('OPTIMAL')
main()


I = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	k = []
	for i in range(n):
		(a, *b) = I()
		k.append(set(b))
	cur = c = b = 0
	vi = set()
	for i in range(n):
		s = k[i] - vi
		if len(s) != 0:
			vi.add(min(s))
		else:
			b = i + 1
	for i in range(1, n + 1):
		if i not in vi:
			cur = i
			break
	if cur == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(b, cur)


t = int(input())
for q in range(t):
	n = int(input())
	d = set()
	p = set()
	for z in range(1, n + 1):
		l = [int(r) for r in input().split()]
		if l[0] == 0:
			d.add(z)
		else:
			c = True
			for s in range(1, len(l)):
				if l[s] not in p:
					p.add(l[s])
					c = False
					break
			if c:
				d.add(z)
	a = 0
	for i in range(1, n + 1):
		if i not in p:
			a = i
			break
	if a:
		print('IMPROVE')
		print(d.pop(), a)
	else:
		print('OPTIMAL')


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
from math import sqrt
t = int(input())
while t:
	d = dd(int)
	n = int(input())
	dif = -1
	for i in range(n):
		l = list(map(int, input().split()))
		lol = 0
		for j in range(1, l[0] + 1):
			if d[l[j]] == 0:
				d[l[j]] = 1
				lol = 1
				break
		if lol == 0 and dif == -1:
			dif = i + 1
	yahi = 0
	for i in range(1, n + 1):
		if d[i] == 0:
			yahi = i
			break
	if dif != -1:
		print('IMPROVE')
		print(dif, yahi)
	else:
		print('OPTIMAL')
	t -= 1


import heapq
import bisect
for tc in range(int(input())):
	n = int(input())
	marriedL = set()
	marriedR = set()
	for i in range(n):
		ls = list(map(int, input().split()))[1:]
		for e in ls:
			if e not in marriedR:
				marriedR.add(e)
				marriedL.add(i + 1)
				break
	if len(marriedL) == n:
		print('OPTIMAL')
	else:
		(ml, mr) = (-1, -1)
		for i in range(1, n + 1):
			if i not in marriedL:
				ml = i
				break
		for i in range(1, n + 1):
			if i not in marriedR:
				mr = i
				break
		print('IMPROVE')
		print(ml, mr)


def opti():
	for j in range(n[i]):
		if not prin[j]:
			for z in range(n[i]):
				if not vis[z]:
					print('IMPROVE')
					print(j + 1, z + 1)
					return
	print('OPTIMAL')
t = int(input())
(n, k) = ([], [])
for i in range(t):
	n.append(int(input()))
	q = []
	for j in range(n[i]):
		q.append([int(i) for i in input().split()])
	k.append(q)
for i in range(t):
	(prin, vis) = ([False] * n[i], [False] * n[i])
	for j in range(n[i]):
		for z in range(1, len(k[i][j])):
			if not vis[k[i][j][z] - 1]:
				vis[k[i][j][z] - 1] = True
				prin[j] = True
				break
	opti()


def main():
	for case in range(int(input())):
		n = int(input())
		final_set = set()
		possiblites = []
		n_flag = False
		for i in range(n):
			temp = [int(x) for x in input().split()]
			k = temp[0]
			princes = set(temp[1:])
			prince = -1
			for x in princes:
				if x not in final_set:
					final_set.add(x)
					prince = x
					break
			if prince == -1:
				n_flag = True
			possiblites.append(prince)
		if n_flag == False:
			print('OPTIMAL')
			continue
		possible_prince = -1
		for i in range(1, n + 1):
			if i not in final_set:
				possible_prince = i
				break
		possible_princess = possiblites.index(-1) + 1
		print('IMPROVE')
		print(possible_princess, possible_prince)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(0, t):
	n = int(input())
	f = []
	for j in range(0, n):
		l = list(map(int, input().split()))
		f.append(l)
	l = [0] * n
	k = [0] * n
	for j in range(0, n):
		for li in range(1, f[j][0] + 1):
			if l[f[j][li] - 1] == 0:
				l[f[j][li] - 1] = 1
				k[j] = 1
				break
	xx = 0
	for j in range(0, n):
		if l[j] == 0:
			mm = j + 1
			xx = -1
			break
	if xx == 0:
		print('OPTIMAL')
	else:
		for j in range(0, n):
			if k[j] == 0:
				print('IMPROVE')
				print(j + 1, mm)
				break


t = int(input())
for u in range(t):
	(x, y) = (-1, -1)
	(n, d, m, k) = (int(input()), dict(), set(), set())
	for i in range(n):
		p = 0
		(s, p) = (input().split()[1:], 0)
		for j in s:
			if j not in k:
				k.add(j)
				m.add(i + 1)
				p = 1
				break
		if p == 0:
			x = i + 1
	if x != -1:
		for i in range(1, n + 1):
			if str(i) not in k:
				y = i
				break
		print('IMPROVE')
		print(str(x) + ' ' + str(y))
	else:
		print('OPTIMAL')


import math
n = input()
for i in range(int(n)):
	m = input()
	plist = [[int(y) for y in input().split(' ')[1:]] for j in range(int(m))]
	prince = set([j + 1 for j in range(int(m))])
	princess = set([j + 1 for j in range(int(m))])
	donep = set()
	for (j, p) in enumerate(plist):
		for el in p:
			if el not in donep:
				minp = el
				prince.remove(minp)
				princess.remove(j + 1)
				donep.add(minp)
				break
	if len(princess) > 0:
		print('IMPROVE')
		print(list(princess)[0], list(prince)[0])
	else:
		print('OPTIMAL')


def noZero(a):
	for i in a:
		if i == 0:
			return False
	return True

def findZero(a):
	for i in range(len(a)):
		if a[i] == 0:
			return i + 1
for _ in range(int(input())):
	n = int(input())
	done = set()
	dau = []
	for i in range(0, n + 1):
		dau.append(0)
	for i in range(1, n + 1):
		liStr = input().split()
		k = int(liStr[0])
		for j in range(1, k + 1):
			pr = int(liStr[j])
			if pr not in done:
				dau[i] = pr
				done.add(pr)
				break
	if noZero(list(dau[1:])):
		print('OPTIMAL')
	else:
		imDau = findZero(list(dau[1:]))
		print('IMPROVE')
		print(imDau, end=' ')
		pr = 0
		for i in range(1, n + 1):
			if i not in done:
				pr = i
				break
		print(pr)


INF = 10 ** 10
TEST_CASES = True

def main():
	n = get_int()
	taken = set()
	mat = []
	for index in range(n):
		mat.append(get_list()[1:])
	waiting = []
	for (index, li) in enumerate(mat):
		done = False
		for i in li:
			if i not in taken:
				taken.add(i)
				done = True
				break
		if not done:
			waiting.append(index + 1)
	if len(waiting) > 0:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in taken:
				print(waiting[0], i)
				return
	else:
		print('OPTIMAL')
import sys
from bisect import bisect_left, bisect_right
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
if not TEST_CASES:
	main()
else:
	[main() for _ in range(int(input()))]
print(*out, sep='\n')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	flag1 = [False] * n
	flag2 = [False] * n
	for i in range(n):
		l = list(map(int, input().split()))
		for li in l[1:]:
			li -= 1
			if not flag2[li]:
				flag1[i] = True
				flag2[li] = True
				break
	c = flag1.count(True)
	if c == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if not flag1[i]:
				print(i + 1, end=' ')
				break
		for i in range(n):
			if not flag2[i]:
				print(i + 1)
				break


for _ in range(int(input())):
	n = int(input())
	d = {}
	p = {}
	for i in range(n):
		d[i + 1] = 0
		p[i + 1] = 0
	for i in range(n):
		(k, *l) = list(map(int, input().split()))
		l = sorted(l)
		while len(l) > 0:
			if d[l[0]] == 0:
				d[l[0]] = i + 1
				p.pop(i + 1)
				break
			else:
				l.remove(l[0])
	if len(p) != 0:
		print('IMPROVE')
		v = list(d.values())
		k = list(d.keys())
		i = v.index(0)
		print(list(p.keys())[0], k[i])
	else:
		print('OPTIMAL')


t = int(input())
for i in range(t):
	n = int(input())
	ml = []
	dl = []
	pl = []
	for j in range(n):
		templ = list(map(int, input().split()))
		l = templ[1:]
		ml.append(l)
		dl.append(0)
		pl.append(0)
	for k in range(len(ml)):
		for m in range(len(ml[k])):
			if pl[ml[k][m] - 1] != 1:
				pl[ml[k][m] - 1] = 1
				dl[k] = 1
				break
			else:
				continue
	if 0 in dl or 0 in pl:
		print('IMPROVE')
		a = dl.index(0)
		b = pl.index(0)
		a = a + 1
		b = b + 1
		print('{} {}'.format(a, b))
	else:
		print('OPTIMAL')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
while t > 0:
	n = int(input())
	princes = set([int(i) for i in range(1, n + 1)])
	dau = []
	for i in range(n):
		dau.append([int(x) for x in input().split()])
	i = 0
	x = 0
	y = 0
	while i < n:
		if len(dau[i]) == 1:
			x = i + 1
		else:
			j = 1
			mar = False
			while j < len(dau[i]):
				if dau[i][j] in princes:
					mar = True
					princes.remove(dau[i][j])
					break
				j += 1
			if mar == False and x == 0:
				x = i + 1
		i += 1
	if len(princes) == 0:
		print('OPTIMAL')
	else:
		for i in princes:
			y = i
			break
		print('IMPROVE')
		print(x, y)
	t -= 1


from sys import stdin
input = stdin.buffer.readline
for i in range(int(input())):
	n = int(input())
	a = set(range(1, n + 1))
	b = a.copy()
	for i in range(1, n + 1):
		for j in [int(i) for i in input().split()][1:]:
			if j in b:
				a.remove(i)
				b.remove(j)
				break
	if a:
		print('IMPROVE')
		print(a.pop(), b.pop())
	else:
		print('OPTIMAL')


import sys
from math import ceil, floor
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
mod = 10 ** 7 + 1
for _ in range(int(ri())):
	n = int(ri())
	arr = []
	for i in range(n):
		temp = RI()
		temp = [i] + temp[1:]
		arr.append(temp)
	s = set()
	pos = -1
	outflag = False
	for i in range(len(arr)):
		flag = False
		if len(arr[i]) == 1:
			flag = False
		for j in range(1, len(arr[i])):
			if arr[i][j] not in s:
				s.add(arr[i][j])
				flag = True
				break
		if not flag and (not outflag):
			pos = arr[i][0]
			outflag = True
	lis = [i for i in s]
	lis.sort()
	lis = [0] + lis + [10 ** 10]
	flag = -1
	for i in range(0, len(lis) - 1):
		if lis[i] + 1 != lis[i + 1]:
			flag = lis[i] + 1
			break
	if len(lis) - 2 == n:
		print('OPTIMAL')
	else:
		if flag == -1:
			flag = 1
		print('IMPROVE')
		print(pos + 1, flag)


for _ in range(int(input())):
	n = int(input())
	dc = {}
	for i in range(1, n + 1):
		dc[i] = []
	prc = [False for i in range(n + 1)]
	pcc = [False for i in range(n + 1)]
	b = []
	for i in range(1, n + 1):
		x = [int(o) for o in input().split()]
		dc[i] = x[1:]
	count = 0
	for i in range(1, n + 1):
		if len(dc[i]) is 0:
			continue
		else:
			temp = dc[i]
			for boy in temp:
				if prc[boy] is False:
					pcc[i] = True
					prc[boy] = True
					count += 1
					break
	if count == n:
		print('OPTIMAL')
	else:
		flag = 0
		for girl in range(1, n + 1):
			if pcc[girl] is False:
				for boy in range(1, n + 1):
					if prc[boy] is False and len(dc[girl]) is 0:
						flag = 1
						print('IMPROVE')
						print(girl, boy)
						break
					elif prc[boy] is False and boy not in dc[girl]:
						flag = 1
						print('IMPROVE')
						print(girl, boy)
						break
			if flag is 1:
				break
		if flag is 0:
			print('OPTIMAL')


from sys import stdin
inp = stdin.readline
t = int(input())
for i in range(t):
	n = int(inp())
	daughters = list()
	freeKingdoms = [0] * n
	freeDaughter = 0
	for j in range(n):
		for k in [int(x) for x in inp().split()][1:]:
			if freeKingdoms[k - 1]:
				continue
			freeKingdoms[k - 1] = 1
			break
		else:
			freeDaughter = j + 1
	if freeDaughter == 0:
		print('OPTIMAL')
	else:
		for j in range(n):
			if not freeKingdoms[j]:
				print('IMPROVE\n' + str(freeDaughter) + ' ' + str(j + 1))
				break
		else:
			print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	not_marred = []
	prince = [0] * n
	for i in range(n):
		f = list(map(int, input().split()))
		k = f[0]
		del f[0]
		for j in range(k):
			if prince[f[j] - 1] == 0:
				prince[f[j] - 1] = 1
				break
		else:
			not_marred.append(i + 1)
	if not_marred == []:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(not_marred[0], prince.index(0) + 1)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	vis = [True] + [False for i in range(n)]
	un = []
	count = 0
	for i in range(1, n + 1):
		l = list(map(int, stdin.readline().split()))
		(num, b) = (l[0], 0)
		for j in range(1, num + 1):
			if not vis[l[j]]:
				vis[l[j]] = True
				b = 1
				count += 1
				break
		if b == 0:
			un.append(i)
	if count == n:
		stdout.write('OPTIMAL' + '\n')
	else:
		for i in range(1, n + 1):
			if not vis[i]:
				break
		stdout.write('IMPROVE' + '\n')
		stdout.write(str(un[0]) + ' ' + str(i) + '\n')


t = int(input())
while t:
	t -= 1
	n = int(input())
	king = [0] * n
	q = -1
	for i in range(n):
		l = list(map(int, input().split(' ')))[1:]
		for j in l:
			if king[j - 1] == 0:
				king[j - 1] = 1
				break
		else:
			q = i
	if q == -1:
		print('OPTIMAL')
	else:
		k = king.index(0)
		print('IMPROVE')
		print(q + 1, k + 1)


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	N = int(input())
	X = [0] * N
	Y = [0] * N
	for i in range(N):
		for a in input().split()[1:]:
			a = int(a) - 1
			if Y[a] == 0:
				Y[a] = 1
				X[i] = 1
				break
	if sum(X) == N:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(max([i for (i, x) in enumerate(X) if x == 0]) + 1, max([i for (i, x) in enumerate(Y) if x == 0]) + 1)


from math import *
from copy import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(l):
	n = len(l)
	princeDone = [0] * n
	princessDone = [0] * n
	for i in range(n):
		f = 1
		for j in l[i]:
			if not princeDone[j - 1]:
				princeDone[j - 1] = 1
				princessDone[i] = 1
				f = 0
				break
	if sum(princeDone) == n:
		print('OPTIMAL')
	else:
		(a, b) = (-1, -1)
		for i in range(n):
			if not princeDone[i] and a == -1:
				a = i
			if not princessDone[i] and b == -1:
				b = i
			if a != -1 and b != -1:
				break
		print('IMPROVE')
		print(b + 1, a + 1)
T = int(input())
for _ in range(T):
	N = int(stdin.readline())
	L = []
	for nn in range(N):
		l = list(map(int, stdin.readline().rstrip().split()))[1:]
		l = sorted(l)
		L.append(l)
	solve(L)


import sys
for i in range(int(input())):
	n = int(sys.stdin.readline())
	d = {}
	ind = {}
	for i in range(1, n + 1):
		a = list(map(int, sys.stdin.readline().split()))
		for j in a[1:]:
			if j not in d:
				d[j] = 1
				break
		else:
			ind[i] = 1
	if len(ind) == 0:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if i not in d:
				break
		for j in ind:
			print('IMPROVE')
			print(j, i)
			break


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def check(A):
	for (i, a) in enumerate(A):
		if a == -1:
			for x in range(1, N + 1):
				if x not in taken:
					ans = (i + 1, x)
					return ans
	return ()
for _ in range(INT()):
	N = INT()
	A = [-1] * N
	taken = set()
	for i in range(N):
		li = LIST()
		(k, li) = (li[0], li[1:])
		for a in li:
			if a not in taken:
				A[i] = a
				taken.add(a)
				break
	ans = check(A)
	if ans:
		print('IMPROVE')
		print(*ans)
	else:
		print('OPTIMAL')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	a = [0] * n
	g = []
	assigned = [0] * n
	unassigned = []
	ans = 'OPTIMAL'
	for i in range(n):
		l = I()
		for j in l[1:]:
			if not assigned[j - 1]:
				assigned[j - 1] = 1
				break
		else:
			unassigned.append(i)
	for i in range(n):
		if not assigned[i]:
			print('IMPROVE')
			print(unassigned[0] + 1, i + 1)
			break
	else:
		print(ans)


import sys
for t in range(int(sys.stdin.readline().strip())):
	n = int(sys.stdin.readline().strip())
	data = set([i for i in range(1, n + 1)])
	data_used = set()
	ans = -1
	for j in range(n):
		pr = list(map(int, input().split()))
		(num, flag) = (pr[0], True)
		for i in range(1, num + 1):
			if pr[i] not in data_used:
				flag = False
				data_used.add(pr[i])
				data.remove(pr[i])
				break
		if flag:
			ans = j + 1
	if ans != -1:
		print('IMPROVE\n', ans, ' ', data.pop(), sep='')
	else:
		print('OPTIMAL')


from sys import stdin, stdout
t = int(stdin.readline())
for p in range(0, t):
	n = int(stdin.readline())
	visited = [0] * (n + 1)
	allprince = set([])
	s = set([])
	princessleft = -1
	for i in range(1, n + 1):
		allprince.add(i)
		a = [int(x) for x in stdin.readline().split()][1:]
		f = 0
		for j in a:
			if visited[j] == 0:
				s.add(j)
				visited[j] = 1
				f = 1
				break
		if f == 0:
			princessleft = i
	if princessleft == -1:
		stdout.write('OPTIMAL\n')
	else:
		ans = allprince.difference(s)
		stdout.write('IMPROVE\n' + str(princessleft) + ' ' + str(ans.pop()) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	check = [0] * n
	cand = []
	for j in range(n):
		l = list(map(int, input().split()))
		marry = False
		for k in l[1:]:
			if check[k - 1] == 0:
				check[k - 1] = 1
				marry = True
				break
		if not marry:
			cand.append(j + 1)
	if not cand:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(cand[0], check.index(0) + 1)


T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	taken = set([])
	unmatched = []
	for i in range(n):
		unmatched_flag = True
		prince_data = list(map(int, input().strip().split()))
		for prince in prince_data[1:]:
			if prince not in taken:
				taken.add(prince)
				unmatched_flag = False
				break
		if unmatched_flag:
			unmatched.append(i)
	if unmatched:
		for prince in range(1, n + 1):
			if prince not in taken:
				break
		print('IMPROVE')
		print(unmatched[0] + 1, prince)
	else:
		print('OPTIMAL')


t = int(input())

def solve(ratings):
	n = len(ratings)
	seen = set([i for i in range(1, n + 1)])
	not_married = 0
	not_married_index = -1
	for (i, prince) in enumerate(ratings):
		for rank in prince:
			if rank in seen:
				seen.remove(rank)
				break
		else:
			not_married += 1
			not_married_index = i + 1
	if not_married:
		print('IMPROVE')
		print(not_married_index, min(seen))
	else:
		print('OPTIMAL')
for i in range(t):
	n = int(input())
	ratings = [[] for _ in range(n)]
	for j in range(n):
		given = list(map(int, input().split(' ')))
		ratings[j] = given[1:]
	solve(ratings)


import sys
import bisect

def main():
	for t in range(int(sys.stdin.readline())):
		n = int(sys.stdin.readline())
		prince = set([j for j in range(n)])
		st = 0
		princes = []
		for i in range(n):
			l = [int(j) for j in sys.stdin.readline().split()]
			len_ = l[0]
			arr = []
			if len_ != 0:
				arr = l[1:]
				for j in range(len_):
					if arr[j] - 1 in prince:
						prince.remove(arr[j] - 1)
						break
					else:
						continue
				else:
					princes.append(i)
			if len_ == 0:
				princes.append(i)
		if len(princes):
			print('IMPROVE')
			print(princes[0] + 1, min(prince) + 1)
		else:
			print('OPTIMAL')
main()


from collections import defaultdict
res = []
t = int(input())
for tt in range(t):
	n = int(input())
	edges = []
	for j in range(n):
		edges.append([int(x) for x in input().split()][1:])
	kingdoms = {i for i in range(1, n + 1)}
	princesses = {i for i in range(n)}
	for j in range(n):
		for edge in edges[j]:
			if edge in kingdoms:
				princesses.remove(j)
				kingdoms.remove(edge)
				break
	try:
		a = princesses.pop()
		b = kingdoms.pop()
		res.append((a + 1, b))
	except:
		res.append(0)
for item in res:
	if type(item) == tuple:
		print('IMPROVE')
		print(item[0], end=' ')
		print(item[1])
	else:
		print('OPTIMAL')


my_int = int
my_range = range
my_input = input
my_print = print
t = my_int(my_input())
for _ in my_range(t):
	n = my_int(my_input())
	prince_married = [False] * n
	unmarried_princess = None
	for i in my_range(n):
		married = False
		princes = my_input().split()[1:]
		for p in princes:
			p = my_int(p) - 1
			if not prince_married[p]:
				prince_married[p] = True
				married = True
				break
		if not married:
			unmarried_princess = i
	if unmarried_princess is None:
		my_print('OPTIMAL')
	else:
		last_prince = prince_married.index(False)
		my_print('IMPROVE')
		my_print(unmarried_princess + 1, last_prince + 1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [0] * (n + 1)
	l1[0] = 1
	l = []
	(l2, f) = ([], 0)
	for _ in range(n):
		x = list(map(int, input().split()))
		l.append(x[1:])
	for i in range(n):
		for j in l[i]:
			if l1[j] == 0:
				l1[j] += 1
				break
		else:
			if f == 0:
				l2.append(i + 1)
				f += 1
	for k in range(1, n + 1):
		if l1[k] == 0:
			l2.append(k)
			break
	if f != 0:
		print('IMPROVE')
		print(*l2)
	else:
		print('OPTIMAL')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	done = [0] * (n + 1)
	free_girl = 0
	for i in range(1, n + 1):
		girl_done = 0
		(k, *rest) = map(int, input().split())
		l = list(rest)
		for j in l:
			if girl_done:
				continue
			if done[j]:
				continue
			done[j] = 1
			girl_done = 1
		if girl_done == 0:
			free_girl = i
	if free_girl == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, len(done)):
			if done[i] == 0:
				print(free_girl, i)
				break


t = int(input())
for test in range(t):
	n = int(input())
	mboy = set()
	count = 0
	unmatched = None
	for girl in range(1, n + 1):
		matched = False
		for boy in list(map(int, input().split()))[1:]:
			if boy not in mboy:
				mboy.add(boy)
				matched = True
				count += 1
				break
		if not matched:
			unmatched = girl
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(unmatched, end=' ')
		for boy in range(1, n + 1):
			if boy not in mboy:
				print(boy)
				break


from sys import stdin, stdout
I = stdin.readline
print = stdout.write
for _ in range(int(I())):
	n = int(I())
	d = []
	k = []
	for i in range(n + 1):
		d.append(0)
		k.append(0)
	t = 0
	for i in range(1, n + 1):
		for j in list(map(int, I().split(' ')))[1:]:
			if k[j] == 0:
				k[j] = 1
				d[i] = 1
				break
		else:
			t = i
	t1 = 0
	if t == 0:
		print('OPTIMAL\n')
	else:
		t1 = k.index(0, 1)
		print('IMPROVE\n')
		print(str(t) + ' ' + str(t1) + '\n')


for t in range(int(input())):
	n = int(input())
	p = [0] * n
	ps = [0] * n
	for N in range(n):
		place = list(map(int, input().split()))
		l = place[0]
		k = place[1:]
		for i in k:
			if p[i - 1] == 0:
				p[i - 1] = 1
				ps[N] = 1
				break
	if p.count(0) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ps.index(0) + 1, ' ', p.index(0) + 1)


for _ in range(int(input())):
	n = int(input())
	s = [0 for i in range(n + 1)]
	ll = []
	for i in range(n):
		l = list(map(int, input().split()))
		k = 1
		while k <= l[0] and s[l[k]] == 1:
			k += 1
		if k <= l[0] and s[l[k]] == 0:
			s[l[k]] = 1
		else:
			ll.append([i, l])
	for i in range(1, len(s)):
		if s[i] == 0 and i <= n:
			break
	if i > n or ll == []:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ll[0][0] + 1, i)


from sys import stdin, stdout
t = int(stdin.readline())
for test in range(t):
	n = int(stdin.readline())
	dicti = {}
	count = 0
	arr = [0] * n
	B_check = False
	ans = [0, 0]
	for test2 in range(1, n + 1):
		line1 = [int(x) for x in stdin.readline().split()]
		S_check = False
		for prince in range(1, len(line1)):
			if line1[prince] not in dicti:
				dicti[line1[prince]] = True
				count = count + 1
				arr[line1[prince] - 1] = prince
				S_check = True
				break
		if S_check == False and B_check == False:
			B_check = True
			ans[0] = test2
	if count == n:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		for i in range(n):
			if arr[i] == 0:
				ans[1] = i + 1
				break
		stdout.write(str(ans[0]) + ' ' + str(ans[1]) + '\n')


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	ar = [[] for x in range(n)]
	c = 0
	good = set(range(1, n + 1))
	free = []
	flag = False
	for i in range(n):
		ar[i] = [int(x) for x in inp().split()]
		ar[i].pop(0)
		ar[i].sort()
	for i in range(n):
		if len(ar[i]) > 0:
			for j in range(len(ar[i])):
				if ar[i][j] in good:
					good.remove(ar[i][j])
					c += 1
					flag = False
					break
				else:
					flag = True
			if flag:
				free.append(i)
		else:
			free.append(i)
	if c == n:
		print('OPTIMAL')
	else:
		for i in good:
			k = i
			break
		for i in free:
			if k not in ar[i]:
				print('IMPROVE')
				print(i + 1, end=' ')
				print(k)
				break


t = int(input())
for i in range(t):
	n = int(input())
	a = [[] for i in range(n)]
	for j in range(n):
		a[j] = list(map(int, input().split()))
		k = a[0]
		a[j].pop(0)
	b = [0 for i in range(n)]
	v = []
	for j in range(n):
		for l in range(len(a[j])):
			if b[a[j][l] - 1] == 0:
				b[a[j][l] - 1] = 1
				break
		else:
			v.append(j)
	if v == []:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		c = 0
		for j in range(n):
			if b[j] == 0:
				for l in range(len(v)):
					if j + 1 not in a[v[l]]:
						print(v[l] + 1, j + 1)
						c = 357
						break
			if c == 357:
				break


t = int(input())
from sys import stdin, stdout
for _ in range(t):
	n = int(input())
	visited = [0] * (n + 1)
	k = 1
	attr = 0
	for i in range(n):
		lis = [int(x) for x in stdin.readline().split()][1:]
		flag = 0
		while lis:
			node = lis.pop(0)
			if visited[node] == 0:
				visited[node] = 1
				flag = 1
				break
		if flag == 0:
			pending = i + 1
			attr = 1
	if attr == 1:
		print('IMPROVE')
		visited = visited[1:]
		i = visited.index(0)
		print(pending, i + 1)
	else:
		print('OPTIMAL')


from sys import stdin, stdout
m = int(stdin.readline())
for _ in range(m):
	v = -1
	n = int(stdin.readline())
	used = [False] * n
	for j in range(n):
		princess = list(map(int, stdin.readline().split(' ')))[1:]
		for i in range(len(princess)):
			if not used[princess[i] - 1]:
				used[princess[i] - 1] = True
				break
		else:
			v = j
	if v == -1:
		stdout.write('OPTIMAL\n')
	else:
		left = used.index(False)
		stdout.write('IMPROVE\n')
		stdout.write('{} {}\n'.format(v + 1, left + 1))


import sys
for _ in range(int(input())):
	n = int(input())
	prince = set(range(1, n + 1))
	princess = set(range(1, n + 1))
	princess_list = [[] for _ in range(n + 1)]
	for i in range(n):
		k = list(map(int, input().split()))[1:]
		princess_list[i + 1] = k
		if k:
			for j in k:
				if j in prince:
					prince.remove(j)
					princess.remove(i + 1)
					break
	tmp = False
	for pr1 in princess:
		for pr2 in prince:
			if pr2 in princess_list[pr1]:
				continue
			else:
				print('IMPROVE')
				print(pr1, pr2)
				tmp = True
				break
		if tmp:
			break
	else:
		print('OPTIMAL')


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
for i in range(int(input())):
	(n, flag) = (int(input()), 0)
	(arr, dis, ext) = ([arr_inp(1) for j in range(n)], set([i for i in range(1, n + 1)]), [])
	for (ix, j) in enumerate(arr):
		if not j[0]:
			ext.append(ix + 1)
		for k in j[1:]:
			if k in dis:
				dis.discard(k)
				flag = 0
				break
			else:
				flag = 1
				continue
		if flag:
			ext.append(ix + 1)
			flag = 0
	if not ext:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ext[0], max(list(dis)))


from collections import defaultdict
t = int(input())
out = []
for _ in range(t):
	n = int(input())
	seen = set()
	missing = None
	for _ in range(n):
		d = list(map(int, input().split()))
		avail = [x for x in d[1:] if x not in seen]
		if not avail:
			missing = _ + 1
		else:
			m = avail[0]
			seen.add(m)
	if missing == None:
		out.append('OPTIMAL')
	else:
		king = min((x for x in range(1, n + 1) if x not in seen))
		out.append('IMPROVE')
		out.append(str(missing) + ' ' + str(king))
print('\n'.join(out))


import itertools
import bisect
import math
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def main():
	for _ in ' ' * int(input()):
		n = ii()
		A = set()
		ind = -1
		for i in range(n):
			aa = lmii()
			a = set()
			nn = len(aa)
			for s in range(1, nn):
				a.add(aa[s])
			if nn == 0:
				ind = i
			else:
				x = a - A
				if x == set():
					ind = i
				else:
					for s in x:
						A.add(s)
						break
		if ind == -1:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			ab = set()
			for i in range(1, n + 1):
				ab.add(i)
			x = ab - A
			for s in x:
				print(ind + 1, s)
				break
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	occured = set()
	for i in range(1, n + 1):
		occured.add(i)
	arr = []
	for i in range(n):
		arr.append(set(l()[1:]))
	answer = 0
	k = []
	for i in range(n):
		r = False
		for j in arr[i]:
			if j in occured:
				answer += 1
				occured.discard(j)
				r = True
				break
		if not r:
			k.append(i)
	result = False
	for i in k:
		for j in occured:
			if j not in arr[i]:
				result = True
				index = i
				value = j
				break
	if result:
		out('IMPROVE\n')
		print(i + 1, j)
		continue
	out('OPTIMAL\n')


import sys
inp = sys.stdin.readline

def input():
	return inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		d = [lin() for i in range(n)]
		done = set()
		d1 = [0] * (n + 1)
		ch = 1
		for i in d:
			if i[0]:
				x = i[1:]
				for j in x:
					if j not in done:
						d1[ch] = j
						done.add(j)
						break
			ch += 1
		left = [i for i in range(1, n + 1) if i not in done]
		ad = []
		for i in range(1, n + 1):
			if d1[i] == 0 and left:
				ad.append((i, left[0]))
				break
		if ad:
			print('IMPROVE')
			print(*ad[0])
		else:
			print('OPTIMAL')
main()


for t in range(int(input())):
	n = int(input())
	vis = [False] * n
	o = -1
	for i in range(n):
		l = list(map(int, input().split()))
		for val in l[1:]:
			if vis[val - 1] == False:
				vis[val - 1] = True
				break
		else:
			o = i
	if o == -1:
		print('OPTIMAL')
	else:
		u = vis.index(False)
		print('IMPROVE')
		print(str(o + 1), str(u + 1))


t = int(input())
for _ in range(t):
	n = int(input())
	d = set()
	temp = -1
	for i in range(n):
		(size, *arr) = map(int, input().split())
		for j in arr:
			if j not in d:
				d.add(j)
				break
		else:
			temp = i + 1
	if temp == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if i not in d:
				print('IMPROVE')
				print(temp, i)
				break


from sys import stdin, stdout
input = stdin.readline
p = stdout.write
for __ in range(int(input())):
	n = int(input())
	d = {}
	rslt = -1
	ind = -1
	for i in range(n):
		a = list(map(int, input().split()))
		temp = 0
		for j in range(1, a[0] + 1):
			if d.get(a[j]) == None:
				d[a[j]] = 1
				temp = 1
				break
		if temp == 0 and rslt == -1:
			rslt = a[1:]
			ind = i + 1
	if len(d.keys()) < n:
		p('IMPROVE' + '\n')
		dd = {}
		for i in range(len(rslt)):
			dd[rslt[i]] = 1
		for i in range(n):
			if d.get(i + 1) == None and dd.get(i + 1) == None:
				ans = i + 1
				break
		p(str(ind) + ' ' + str(ans) + '\n')
	else:
		p('OPTIMAL' + '\n')
	stdout.flush()


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	graph = [[]]
	for i in range(N):
		A = list(map(int, input().split()))
		graph.append(A[1:])
	Query.append((N, graph))
for (N, graph) in Query:
	Man = set([i + 1 for i in range(N)])
	Woman = set()
	for woman in range(1, N + 1):
		decided = False
		for pair in graph[woman]:
			if pair in Man:
				Man.remove(pair)
				decided = True
				break
		if not decided:
			Woman.add(woman)
	if not Man:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		a1 = min(Man)
		a2 = min(Woman)
		print(a2, a1)


def solve():
	n = int(input())
	a = []
	princes = set(range(1, n + 1))
	for i in range(n):
		wanted = set(map(int, input().split()[1:]))
		married = False
		for wi in wanted:
			if wi in princes:
				married = True
				princes.remove(wi)
				break
		if not married:
			a.append((i + 1, wanted))
	if len(princes) == 0:
		return None
	return (a[0][0], list(princes)[0])
for i in range(int(input())):
	result = solve()
	if result:
		print('IMPROVE')
		print(*result)
	else:
		print('OPTIMAL')


t = int(input())
r = []
for i in range(t):
	n = int(input())
	p = [0] * n
	y = 0
	for www in range(n):
		k = [int(x) for x in input().split()]
		e = 0
		for j in k[1:]:
			if j == 0:
				break
			elif p[j - 1] == 0:
				p[j - 1] = 1
				e = 1
				break
		if e == 0 and y == 0:
			y = www + 1
		if www == n - 1:
			if y != 0:
				for m in range(1, n + 1):
					if p[-m] != 1:
						r.append(str(y) + ' ' + str(n - m + 1))
						break
			else:
				r.append('OPTIMAL')
for i in r:
	if i == 'OPTIMAL':
		print(i)
	else:
		print('IMPROVE')
		print(i)


import sys
import math
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	notmarried = -1
	prince = [0 for i in range(n)]
	for j in range(n):
		(k, *arr) = [int(c) for c in input().split()]
		for i in arr:
			if prince[i - 1] == 0:
				prince[i - 1] = 1
				break
		else:
			notmarried = j
	if notmarried >= 0:
		print('IMPROVE')
		print(notmarried + 1, prince.index(0) + 1)
	else:
		print('OPTIMAL')


def slv(n, g):
	v = set([i for i in range(n)])
	m = [False for i in range(n)]
	for i in range(n):
		for j in g[i]:
			if j in v:
				v.remove(j)
				m[i] = True
				break
	nm = [i for i in range(n) if m[i] == False]
	if not nm:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print('{} {}'.format(nm[0] + 1, list(v)[0] + 1))
t = int(input())
for _ in range(t):
	n = int(input())
	g = []
	for _ in range(n):
		a = list(map(int, input().split()))
		a = [i - 1 for i in a[1:]]
		g.append(a)
	slv(n, g)


for _ in range(int(input())):
	n = int(input())
	used = [False] * n
	single = -1
	for i in range(n):
		a = [int(x) - 1 for x in input().split()][1:]
		for x in a:
			if not used[x]:
				used[x] = True
				break
		else:
			single = i
	if single != -1:
		prince = used.index(False)
		print('IMPROVE\n' + str(single + 1) + ' ' + str(prince + 1))
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	married = set()
	daughter = None
	for i in range(1, n + 1):
		line = list(map(int, input().split()))
		a = set(line[1:])
		m = None
		for x in a:
			if x not in married:
				if m == None or x < m:
					m = x
		if m != None:
			married.add(m)
		else:
			daughter = i
	if daughter != None:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in married:
				print(daughter, i)
				break
	else:
		print('OPTIMAL')


from functools import lru_cache
t = int(input())
for _ in range(t):
	n = int(input())
	g = []
	for i in range(n):
		tmp = list(map(int, input().split(' ')))
		if tmp[0] >= 1:
			g.append(tmp[1:])
		else:
			g.append([])
	visited = [1 for i in range(n + 1)]
	visited[0] = 0
	married = [0 for i in range(n + 1)]
	for i in range(len(g)):
		for j in range(len(g[i])):
			if visited[g[i][j]] == 1:
				visited[g[i][j]] = 0
				married[i + 1] = 1
				break
	if sum(visited) == 0:
		print('OPTIMAL')
	else:
		print(f'IMPROVE')
		for i in range(1, n + 1):
			if married[i] == 0:
				print(i, end=' ')
				break
		for i in range(1, n + 1):
			if visited[i] == 1:
				print(i)
				break


for _ in range(int(input())):
	n = int(input())
	ls = []
	for i in range(n):
		ls.append(list(map(int, input().split()))[1:])
	pr = [True] * n
	mr = [False] * n
	c = 0
	for i in range(n):
		k = ls[i]
		for j in k:
			if pr[j - 1]:
				pr[j - 1] = False
				mr[i] = True
				c += 1
				break
	if c == n:
		print('OPTIMAL')
	else:
		a = 0
		b = 0
		for i in range(n):
			if not mr[i]:
				a = i + 1
				break
		for i in range(n):
			if pr[i]:
				b = i + 1
				break
		print('IMPROVE')
		print(a, b)


t = int(input())
while t > 0:
	n = int(input())
	d = [False] * (n + 1)
	p = [False] * (n + 1)
	for i in range(1, n + 1):
		a = list(map(int, input().split()))[1:]
		for j in a:
			if not p[j]:
				p[j] = True
				d[i] = True
				break
	(da, pi) = (-1, -1)
	for i in range(1, n + 1):
		if not p[i]:
			pi = i
		if not d[i]:
			da = i
	if da == -1 or pi == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(f'{da} {pi}')
	t = t - 1


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split()))[1:])
	d = {}
	l = {}
	for i in range(n):
		flag = 0
		for j in a[i]:
			if j not in d:
				d[j] = 1
				flag = 1
				break
		if not flag:
			l[i] = 1
	if len(l) == 0:
		print('OPTIMAL')
		continue
	print('IMPROVE')
	for i in l:
		ans = i
		break
	for i in range(1, n + 1):
		if i not in d:
			print(ans + 1, i)
			break


from sys import stdin, stdout
T = int(stdin.readline())
for i in range(T):
	N = int(stdin.readline())
	daughterToImprove = -1
	used = [False for i in range(N)]
	for k in range(N):
		daughter = [int(x) - 1 for x in stdin.readline().split()][1:]
		for prince in daughter:
			if used[prince] == False:
				used[prince] = True
				break
		else:
			daughterToImprove = k
	if daughterToImprove == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print('{} {}'.format(daughterToImprove + 1, used.index(False) + 1))


def solve():
	n = int(input())
	prince = [False] * n
	improved = []
	for i in range(n):
		picks = list(map(int, input().split()))
		milgya = False
		for j in range(1, len(picks)):
			if not prince[picks[j] - 1]:
				milgya = True
				prince[picks[j] - 1] = True
				break
		if not milgya:
			improved.append(i + 1)
	if improved == []:
		print('OPTIMAL')
		return
	print('IMPROVE')
	print(improved[0], prince.index(False) + 1)
	return
t = int(input())
while t != 0:
	res = solve()
	t -= 1


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	d = defaultdict(int)
	flag1 = 0
	index = set([i for i in range(1, n + 1)])
	s = set()
	for j in range(n):
		k = list(map(int, input().split()))
		flag = 0
		for i in k[1:]:
			if d[i] == 0:
				flag = 1
				d[i] = 1
				s.add(i)
				break
			else:
				continue
		if flag == 0:
			new_ind = j + 1
			flag1 = 1
	if flag1 == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(new_ind, (index - s).pop())


import math, collections, sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = []
	vis1 = [0 for i in range(n)]
	vis2 = [0 for i in range(n + 1)]
	for i in range(n):
		a.append(list(map(int, input().split()))[1:])
		for j in a[i]:
			if not vis2[j]:
				vis2[j] = 1
				vis1[i] = 1
				break
	for i in range(n):
		if not vis1[i]:
			print('IMPROVE')
			for j in range(1, n + 1):
				if not vis2[j]:
					print(i + 1, j)
					return
	print('OPTIMAL')
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	kingdoms = [0] * (n + 1)
	is_married = [0] * (n + 1)
	is_optimal = True
	for j in range(n):
		g = list(map(int, input().split(' ')))
		for k in range(1, g[0] + 1):
			if kingdoms[g[k]] == 0:
				kingdoms[g[k]] = 1
				is_married[j + 1] = 1
				break
	for j in range(1, n + 1):
		if is_married[j] == 0:
			is_optimal = False
			print('IMPROVE')
			for l in range(1, n + 1):
				if kingdoms[l] == 0:
					print(j, l)
					break
			break
	if is_optimal:
		print('OPTIMAL')


t = int(input())
setups = []
for _ in range(t):
	n = int(input())
	setup = []
	for _ in range(n):
		count_and_list = input().split(' ')
		if len(count_and_list) == 1:
			husbands = tuple()
		else:
			husbands = tuple((int(x) for x in count_and_list[1:]))
		setup.append(husbands)
	setups.append(setup)

def process(setup):
	available_husbands = set(range(1, len(setup) + 1))
	for (daughter_index, daughter_prefs) in enumerate(setup, 1):
		took_someone = False
		for husband in daughter_prefs:
			if husband in available_husbands:
				took_someone = True
				available_husbands.remove(husband)
				break
		if not took_someone:
			bad_daughter = daughter_index
	if len(available_husbands) > 0:
		print('IMPROVE')
		print(f'{bad_daughter} {available_husbands.pop()}')
	else:
		print('OPTIMAL')
for setup in setups:
	process(setup)


import sys
input = sys.stdin.buffer.readline

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	n = int(input())
	arrs = [[]] * n
	doned = [False] * n
	donepr = [False] * n
	for i in range(n):
		arrs[i] = I()
		m = arrs[i][0]
		if m:
			for j in arrs[i][1:]:
				if not donepr[j - 1]:
					donepr[j - 1] = True
					doned[i] = True
					break
	d = -1
	p = -1
	for i in range(n):
		if not doned[i]:
			d = i + 1
	for i in range(n):
		if not donepr[i]:
			p = i + 1
	if d == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(d, p)


t = int(input())
used = [-1] * 10 ** 5
for test in range(t):
	n = int(input())
	p = -1
	for i in range(n):
		arr = [int(c) - 1 for c in input().split()]
		for u in arr[1:]:
			if used[u] != test:
				used[u] = test
				break
		else:
			p = i
	if p == -1:
		print('OPTIMAL')
		continue
	print('IMPROVE')
	for i in range(n):
		if used[i] != test:
			print(p + 1, i + 1)
			break


for _ in range(int(input())):
	n = int(input())
	prince = [0] * (n + 1)
	for i in range(1, n + 1):
		prince[i] = list(map(int, input().split()))[1:]
	a = [0] * (n + 1)
	b = [0] * (n + 1)
	for i in range(1, n + 1):
		for j in prince[i]:
			if a[j] == 0:
				a[j] = 1
				b[i] = 1
				break
	if sum(b) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(b.index(0, 1), a.index(0, 1))


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def ddd():
	return collections.defaultdict(collections.defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(ii()):
	n = ii()
	d = [0 for i in range(n + 1)]
	k = [0 for i in range(n + 1)]
	(d[0], k[0]) = (1, 1)
	for i in range(n):
		tmp = li()
		for j in range(1, tmp[0] + 1):
			if k[tmp[j]] == 0:
				d[i + 1] = tmp[j]
				k[tmp[j]] = i + 1
				break
	if 0 in d:
		(i, j) = (d.index(0), k.index(0))
		print('IMPROVE')
		print(i, j)
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	N = int(input())
	MyDict = {}
	Number = 0
	Check = [False] * N
	Kingdom = [False] * N
	for i in range(N):
		X = list(map(int, input().split()))
		for j in range(X[0]):
			if MyDict.get(X[j + 1]) == None:
				MyDict[X[j + 1]] = True
				Kingdom[X[j + 1] - 1] = True
				Check[i] = True
				Number += 1
				break
	if Number == N:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(Check.index(False) + 1, Kingdom.index(False) + 1)


T = int(input())
for _ in range(T):
	n = int(input())
	a1 = [0] * n
	k1 = [0] * n
	for i in range(n):
		l = list(map(int, input().split()))
		for j in range(1, len(l)):
			u = l[j]
			if k1[u - 1] == 0:
				k1[u - 1] = 1
				a1[i] = 1
				break
			else:
				pass
	if a1.count(1) == n and k1.count(1) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		q = a1.index(0)
		e = k1.index(0)
		print(q + 1, e + 1)
		continue


from sys import stdin
inf = stdin

def help():
	n = int(inf.readline())
	visited = [0] * n
	helper = None
	for i in range(n):
		flag = False
		arr = list(map(int, inf.readline().split(' ')))
		for j in range(1, arr[0] + 1):
			if not visited[arr[j] - 1]:
				flag = True
				visited[arr[j] - 1] = True
				break
		if not flag:
			helper = i + 1
	for i in range(n):
		if not visited[i]:
			print('IMPROVE')
			print(helper, i + 1)
			return
	print('OPTIMAL')
for qw in range(int(inf.readline())):
	help()


from sys import stdin
t = int(input())
for i in range(t):
	n = int(input())
	q = [0 for i in range(n)]
	c = 0
	for j in range(n):
		boo = 0
		for k in [int(i) for i in stdin.readline().split()][1:]:
			if q[k - 1] == 1:
				continue
			q[k - 1] = 1
			boo = 1
			break
		c += boo
		if boo == 0:
			xex = j
	if c == n:
		print('OPTIMAL')
		continue
	for u in range(n):
		if q[u] == 0:
			ind = u
			break
	print('IMPROVE')
	print(xex + 1, ind + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	proceed = [False] * (n + 1)
	to_check = -1
	for __ in range(n):
		princess = list(map(int, input().split()))
		if princess[0] != 0:
			i = 1
			nieznaleziono = False
			while proceed[princess[i]] != False:
				if i == princess[0]:
					nieznaleziono = True
					break
				i += 1
			if nieznaleziono == True:
				to_check = __ + 1
			else:
				proceed[princess[i]] = True
		else:
			to_check = __ + 1
	if to_check != -1:
		counter = 1
		for x in proceed[1:]:
			if x == False:
				print('IMPROVE')
				print(to_check, ' ', counter)
				break
			counter += 1
	else:
		print('OPTIMAL')


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(input())
	a = []
	dich = {}
	dicw = {}
	for i in range(n):
		dicw[i + 1] = 0
		dich[i + 1] = 0
	for i in range(n):
		for k in [int(x) for x in stdin.readline().split()][1:]:
			if dich[k] == 0:
				dich[k] = 1
				dicw[i + 1] = 1
				break
	h = -1
	w = -1
	for i in range(1, n + 1):
		if dicw[i] == 0:
			w = i
		if dich[i] == 0:
			h = i
	if h == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(w, h)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	takenDaughter = [False for __ in range(n)]
	takenKingdom = [False for __ in range(n)]
	for daughter in range(n):
		temp = [int(x) for x in input().split()][1:]
		for kingdom in temp:
			kingdom -= 1
			if takenKingdom[kingdom] == False:
				takenKingdom[kingdom] = True
				takenDaughter[daughter] = True
				break
	untakenDaughter = -1
	untakenKingdom = -1
	for i in range(n):
		if takenDaughter[i] == False:
			untakenDaughter = i
		if takenKingdom[i] == False:
			untakenKingdom = i
	if untakenDaughter != -1 and untakenKingdom != -1:
		print('IMPROVE')
		print('{} {}'.format(untakenDaughter + 1, untakenKingdom + 1))
	else:
		print('OPTIMAL')


for t in range(int(input())):
	n = int(input())
	daughter = ['$'] * n
	chosen = {}
	for i in range(n):
		chosen[i] = False
	left = []
	for i in range(n):
		l = list(map(int, input().split()))
		x = l[1:]
		found = False
		for j in x:
			if chosen[j - 1]:
				continue
			else:
				found = True
				chosen[j - 1] = True
				break
		if found:
			daughter[i] = j
		else:
			left.append(i)
	if len(left) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in chosen.keys():
			if not chosen[i]:
				break
		print(left[0] + 1, i + 1)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		b = list(map(int, input().split()))
		a.append(b[1:])
	d = {i: 0 for i in range(1, n + 1)}
	p = -1
	for i in range(n):
		for j in a[i]:
			if d[j] == 0:
				d[j] = 1
				break
		else:
			p = i + 1
	if p == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if d[i] == 0:
				print(p, i)
				break


t = int(input())
for _ in range(t):
	n = int(input())
	x = [0] * (n + 1)
	count = 0
	L = []
	N = []
	for i in range(n):
		Li = list(map(int, input().split()))
		L.append(Li)
	for k in range(n):
		i = L[k]
		c = 0
		for j in range(1, i[0] + 1):
			if x[i[j]] == 0:
				x[i[j]] = 1
				count += 1
				c += 1
				break
		if c == 0:
			N.append(k + 1)
		if count == n:
			break
	if count == n or len(N) == 0:
		print('OPTIMAL')
	else:
		del x[0]
		i = x.index(0)
		i += 1
		print('IMPROVE')
		print(N[0], i)


import bisect
import os
import io
from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce
from collections import deque
import threading

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	n = iinput()
	val = []
	for i in range(n):
		a = rlinput()
		a.pop(0)
		val.append(a)
	ans1 = -1
	visited = [False] * (n + 1)
	for i in range(n):
		flag = False
		for j in val[i]:
			if not visited[j]:
				visited[j] = True
				flag = True
				break
		if not flag:
			ans1 = i + 1
	if ans1 == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		ans2 = -1
		for i in range(1, n + 1):
			if not visited[i]:
				ans2 = i
				break
		print(ans1, ans2)


t = int(input())
for qrwq in range(t):
	n = int(input())
	dou = [[]] * n
	not_dou = []
	for i in range(n):
		dou[i] = [int(f) - 1 for f in input().split()]
		dou[i].pop(0)
	prince = [0] * n
	for i in range(n):
		for j in dou[i]:
			if prince[j] == 0:
				prince[j] = 1
				break
		else:
			not_dou.append(i)
	if prince.count(1) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(not_dou[0] + 1, prince.index(0) + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	k = []
	for _ in range(n):
		k.append(list(map(int, input().split())))
	knd = [False] * n
	problem = -1
	free = 0
	for i in range(n):
		ok = False
		for j in range(1, len(k[i])):
			if not knd[k[i][j] - 1]:
				knd[k[i][j] - 1] = True
				ok = True
				break
		if not ok and problem == -1:
			problem = i
	if False in knd:
		free = knd.index(False)
	if problem == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(problem + 1, free + 1)


for faskfhsa in range(int(input())):
	n = int(input())
	king = [0] * n
	queen = [0] * n
	b = []
	left = []
	for i in range(n):
		qw = list(map(int, input().split()))
		b.append(qw)
	for i in range(n):
		if b[i][0] == 0:
			left.append(i)
			continue
		for j in range(1, len(b[i])):
			if king[b[i][j] - 1] == 0:
				king[b[i][j] - 1] = 1
				queen[i] = 1
				break
		if queen[i] != 1:
			left.append(i)
	if len(left) == 0:
		print('OPTIMAL')
	else:
		count = 0
		print('IMPROVE')
		for i in range(n):
			if king[i] == 0:
				print(left[0] + 1, i + 1)
				break


from collections import defaultdict
for _ in range(int(input())):
	N = int(input())
	Hash = defaultdict(lambda : 0)
	Shadi = defaultdict(lambda : 0)
	for i in range(N):
		L = list(map(int, input().split()))
		n = L[0]
		for j in range(1, n + 1):
			if Hash[L[j]] == 0:
				Shadi[i + 1] = 1
				Hash[L[j]] = 1
				break
	FLAG = 0
	index = 0
	for i in range(1, N + 1):
		if Shadi[i] == 0:
			FLAG = 1
			index = i
			break
	if FLAG == 0:
		print('OPTIMAL')
	else:
		for i in range(1, N + 1):
			if Hash[i] == 0:
				ans = i
				break
		print('IMPROVE')
		print(index, ans)


for t in range(int(input())):
	n = int(input())
	a = set()
	c = 0
	b = set()
	r = []
	for i in range(n):
		l = [int(x) for x in input().split()]
		z = l[0]
		r.append(l)
		for j in range(z):
			if l[j + 1] not in a:
				a.add(l[j + 1])
				b.add(i + 1)
				c += 1
				break
	if c == n:
		print('OPTIMAL')
	else:
		y = 0
		for i in range(1, n + 1):
			if i not in b:
				for j in range(1, n + 1):
					if j not in a:
						print('IMPROVE')
						print(i, j)
						y = 1
						break
			if y == 1:
				break
		if y != 1:
			print('OPTIMAL')


from sys import stdin
t = int(stdin.readline())
for _ in range(0, t):
	n = int(input())
	princes = [False] * n
	isPrincessUnmatched = True
	unmatchedPrincess = -1
	for i in range(0, n):
		l = [int(x) - 1 for x in stdin.readline().split()][1:]
		isPrincessUnmatched = True
		for j in l:
			if not princes[j]:
				princes[j] = True
				isPrincessUnmatched = False
				break
		if isPrincessUnmatched:
			unmatchedPrincess = i
	if unmatchedPrincess != -1:
		print('IMPROVE')
		print(unmatchedPrincess + 1, princes.index(False) + 1)
	else:
		print('OPTIMAL')


def solve(i, n):
	kingdom_married = [False] * n
	failed = -1
	for d in range(n):
		hopes = [int(a) for a in input().split()[1:]]
		married = False
		for hope in hopes:
			if not kingdom_married[hope - 1]:
				kingdom_married[hope - 1] = True
				married = True
				break
		if not married:
			failed = d
	if failed == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		kingdom = -1
		for d in range(n):
			if not kingdom_married[d]:
				kingdom = d
				break
		print('{0} {1}'.format(failed + 1, kingdom + 1))
t = int(input())
for i in range(t):
	n = int(input())
	solve(i + 1, n)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		taken = [False for i in range(n)]
		unmarriedPrincess = -1
		for i in range(n):
			options = list(map(lambda x: int(x) - 1, input().split()))[1:]
			for j in options:
				if not taken[j]:
					taken[j] = True
					break
			else:
				unmarriedPrincess = i
		if unmarriedPrincess == -1:
			print('OPTIMAL')
		else:
			unmarriedPrince = taken.index(False)
			print('IMPROVE')
			print(f'{unmarriedPrincess + 1} {unmarriedPrince + 1}')
main()


import math

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
t = int(input())
for _ in range(t):
	n = int(input())
	used = [False for i in range(n)]
	v = -1
	for i in range(n):
		l = list(map(int, input().split()))[1:]
		for j in l:
			if not used[j - 1]:
				used[j - 1] = True
				break
		else:
			v = i
	if v == -1:
		print('OPTIMAL')
	else:
		u = used.index(False)
		print('IMPROVE\n' + str(v + 1) + ' ' + str(u + 1))


t = int(input())
for _ in range(t):
	n = int(input())
	married_king = [False] * (n + 1)
	singles = []
	for i in range(1, n + 1):
		married = False
		kings = list(map(int, input().split()))
		for j in range(1, len(kings)):
			if not married_king[kings[j]]:
				married_king[kings[j]] = True
				married = True
				break
		if not married:
			singles.append(i)
	if len(singles) == 0:
		print('OPTIMAL')
	else:
		king_to_be_married = 0
		for i in range(1, len(married_king))[::-1]:
			if not married_king[i]:
				king_to_be_married = i
				break
		print('IMPROVE')
		print('{} {}'.format(singles[-1], king_to_be_married))


from functools import lru_cache
t = int(input())
for _ in range(t):
	n = int(input())
	g = [[] for _ in range(n)]
	for i in range(n):
		tmp = list(map(int, input().split(' ')))
		if tmp[0] >= 1:
			arr = tmp[1:]
			g[i].extend(arr)
	kings = set([i for i in range(1, n + 1)])
	unm = set([i for i in range(1, n + 1)])
	for i in range(n):
		for king in g[i]:
			if king in kings:
				kings.remove(king)
				unm.remove(i + 1)
				break
	if len(unm) == 0 or len(kings) == 0:
		print('OPTIMAL')
		continue
	else:
		print('IMPROVE')
		print(f'{unm.pop()} {kings.pop()}')


def solve():
	n = int(input())
	h = []
	for i in range(n):
		h.append(0)
	s1 = []
	for i in range(n):
		flag = 0
		l1 = list(map(int, input().split()))
		k1 = l1.pop(0)
		for j in range(k1):
			r1 = l1[j] - 1
			if h[r1] == 0:
				h[r1] = 1
				flag = 1
				break
		if flag == 0:
			s1.append(i + 1)
	if len(s1) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(s1[0], end=' ')
		for i in range(n):
			if h[i] == 0:
				print(i + 1)
				break
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	visited = set()
	improve = -1
	for i in range(n):
		s = input()
		if '0' == s:
			if improve == -1:
				improve = i + 1
			continue
		d = list(map(int, s[s.find(' ') + 1:].split()))
		d.sort()
		for j in range(len(d)):
			if d[j] not in visited:
				visited.add(d[j])
				break
		else:
			if improve == -1:
				improve = i + 1
	if improve == -1:
		print('OPTIMAL')
	else:
		for i in range(1, n + 1):
			if i not in visited:
				print('IMPROVE')
				print(improve, i)
				break


for _ in range(int(input())):
	n = int(input())
	dic = {}
	m = {}
	boo = True
	ans = 0
	for i in range(n):
		a = [int(j) for j in input().split()]
		boo = True
		for j in a[1:]:
			if j not in m.keys():
				m[j] = i + 1
				boo = False
				break
		if boo:
			ans = i + 1
	ans2 = list(set((x for x in range(1, n + 1))) - set(m.keys()))
	if len(ans2) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(ans, ans2[0])


t = int(input())
for _ in range(t):
	n = int(input())
	allowed = []
	for i in range(n):
		arr = list(map(int, input().strip().split()))
		allowed.append(arr)
	prince = dict()
	for i in range(1, n + 1):
		prince[i] = 0
	princess = dict()
	for i in range(1, n + 1):
		princess[i] = 0
	for i in range(n):
		for j in range(allowed[i][0]):
			if prince.get(allowed[i][j + 1]) == 0:
				prince[allowed[i][j + 1]] += 1
				princess[i + 1] = 1
				break
	flg = 0
	for i in range(1, n + 1):
		if princess.get(i) == 0:
			daughter = i
			flg = 1
			break
	if flg == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if prince.get(i) == 0:
				kingdom = i
				flg = 1
				break
		print(daughter, kingdom)


import os, sys, atexit
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
t = int(int(input()))
while t:
	t += -1
	n = int(input())
	arr = [0]
	for i in range(n):
		temp = list(map(int, input().split()))
		arr.append(temp)
	marr = [0] * (n + 1)
	king = [0] * (n + 1)
	for i in range(1, n + 1):
		for j in range(1, arr[i][0] + 1):
			if king[arr[i][j]] != 1:
				king[arr[i][j]] = 1
				marr[i] = arr[i][j]
				break
	ch = 0
	for i in range(1, n + 1):
		if marr[i] == 0:
			ch = i
			break
	if ch == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if king[i] == 0:
				print(ch, i)
				break


from collections import deque
import sys

def main():
	for _ in range(int(sys.stdin.readline())):
		n = int(sys.stdin.readline())
		a = []
		for i in range(n):
			ll = list(map(int, sys.stdin.readline().split()))
			ll = ll[1:]
			ll = deque(ll)
			a.append(ll)
		used = set()
		done = set()
		undone = set()
		unused = set()
		for i in range(n):
			while a[i] and a[i][0] in used:
				a[i].popleft()
			if a[i]:
				done.add(i + 1)
				used.add(a[i][0])
				a[i].popleft()
			else:
				undone.add(i)
		if len(undone) == 0:
			print('OPTIMAL')
		else:
			j = 1
			while j in used and j <= n:
				j += 1
			print('IMPROVE')
			undone = list(undone)
			print(undone[0] + 1, j)
main()


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(2 * 10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		st = set()
		temp = []
		for j in range(n):
			ar = inpt()
			mn = 10 ** 9
			for i in range(1, len(ar)):
				if ar[i] not in st:
					mn = min(mn, ar[i])
			if mn == 10 ** 9:
				temp.append(j + 1)
			else:
				st.add(mn)
		if len(temp) == 0:
			print('OPTIMAL')
		else:
			for i in range(1, n + 1):
				if i not in st:
					print('IMPROVE')
					print(temp[0], i)
					break
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
input = stdin.readline
import math
for i in range(int(input())):
	n = int(input())
	pos = -1
	has = [0] * (n + 1)
	for i in range(n):
		arr = list(map(int, input().split()))
		sorted(arr[1:-1])
		p = -1
		for j in range(1, arr[0] + 1):
			if not has[arr[j]]:
				p = arr[j]
				has[arr[j]] = 1
				break
		if p == -1:
			pos = i
	if pos == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if not has[i]:
				print(pos + 1, i)
				break


from sys import stdin, stdout
t = int(input())
for tt in range(t):
	g = -1
	n = int(input())
	b = [False for i in range(n)]
	for i in range(n):
		a = [int(x) - 1 for x in stdin.readline().split()][1:]
		for j in a:
			if not b[j]:
				b[j] = True
				break
		else:
			g = i
	if g == -1:
		print('OPTIMAL')
	else:
		u = b.index(False)
		print('IMPROVE ', g + 1, ' ', u + 1)


q = int(input())
for i in range(q):
	n = int(input())
	p = []
	for j in range(n):
		k = list(map(int, input().split()))
		p.append(k)
	u = []
	for j in range(n):
		u.append(0)
	v = -1
	for j in range(n):
		s = 0
		for k in range(1, p[j][0] + 1):
			if u[p[j][k] - 1] == 0:
				u[p[j][k] - 1] = 1
				s = 1
				break
		if s == 0:
			v = j + 1
	if v == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(str(v) + ' ' + str(u.index(0) + 1))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = [LI_()[1:] for _ in range(n)]
		b = [0] * n
		o = [0] * n
		r = None
		for i in range(n):
			ok = False
			for c in a[i]:
				if b[c] == 0:
					b[c] = 1
					ok = True
					break
			if ok:
				o[i] = 1
		for i in range(n):
			if o[i] == 1:
				continue
			for c in range(n):
				if b[c] == 0:
					r = (i + 1, c + 1)
					break
			break
		if r:
			rr.append('IMPROVE')
			rr.append(JA(r, ' '))
		else:
			rr.append('OPTIMAL')
	return JA(rr, '\n')
print(main())


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	N = int(input())
	G = []
	for _ in range(N):
		(_, *g) = map(int, input().split())
		G.append(g)
	Prince = [1] * (N + 1)
	dr = None
	for (d, g) in enumerate(G, 1):
		for gg in g:
			if Prince[gg] == 1:
				Prince[gg] = 0
				break
		else:
			if dr is None:
				dr = d
	if dr is None:
		print('OPTIMAL')
	else:
		Prince[0] = 0
		print('IMPROVE')
		print(dr, Prince.index(1))


for T in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		a = list(map(int, input().split()))
		arr.append(a[1:])
	d = {}
	u = []
	for i in range(n):
		cnt = 0
		for j in arr[i]:
			if not d.get(j, 0):
				d[j] = 1
				break
			else:
				cnt += 1
		if cnt == len(arr[i]):
			u.append(i + 1)
	if len(u) >= 1:
		p = u[0]
		for i in range(1, n + 1):
			if not d.get(i, 0):
				print('IMPROVE')
				print(p, i)
				break
	else:
		print('OPTIMAL')


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	kingdom = []
	for k in range(n):
		order = [int(i) for i in input().split() if i != '\n']
		kingdom.append(order[1:])
	(visited, married) = ([0] * n, [False] * n)
	for i in range(n):
		for j in kingdom[i]:
			if visited[j - 1] == 0:
				visited[j - 1] = 1
				married[i] = True
				break
	ok = False
	for j in range(len(married)):
		if married[j] == False:
			for k in range(len(visited)):
				if visited[k] == 0:
					if k + 1 not in kingdom[j]:
						ans = [j + 1, k + 1]
						ok = True
						break
			if ok == True:
				break
		if ok == True:
			break
	if ok == True:
		print('IMPROVE')
		print(*ans)
	else:
		print('OPTIMAL')


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip()
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
t = int(input())
for _ in range(t):
	n = int(input())
	g = [[] for _ in range(n)]
	for i in range(n):
		a = [int(x) for x in input().split()]
		for j in range(1, len(a)):
			g[i].append(a[j])
	principes = set()
	princesas = set()
	for i in range(n):
		for j in range(len(g[i])):
			if g[i][j] in principes:
				continue
			else:
				principes.add(g[i][j])
				princesas.add(i + 1)
				break
	if len(principes) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in principes:
				b = i
			if i not in princesas:
				a = i
		print(a, b)


for _ in range(int(input())):
	n = int(input())
	b = [-1] * (n + 1)
	a = 0
	c = 0
	for j in range(n):
		g = list(map(int, input().split()))
		a = 0
		for i in range(1, len(g)):
			if b[g[i]] == -1:
				b[g[i]] = 1
				a = 1
				break
		if a == 0:
			c = j + 1
	if c == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, n + 1):
			if b[i] == -1:
				print(c, i)
				break


from sys import stdin, stdout
from collections import defaultdict
from functools import lru_cache
from math import gcd, floor, ceil

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

def iint():
	return int(stdin.readline())

def istr():
	return stdin.readline()
for _ in range(iint()):
	d = iint()
	Plist = []
	for _k in range(d):
		Plist.append(ilist())
	princess = set()
	princes = set()
	for (i, p) in enumerate(Plist, 1):
		for x in p[1:]:
			if x not in princes:
				princess.add(i)
				princes.add(x)
				break
	p = list(set(range(1, d + 1)).difference(princess))
	q = list(set(range(1, d + 1)).difference(princes))
	if p and q:
		stdout.write('IMPROVE' + '\n' + str(p[0]) + ' ' + str(q[0]) + '\n')
	else:
		stdout.write('OPTIMAL' + '\n')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	is_taken = [False] * n
	free = None
	for i in range(n):
		line = [int(item) - 1 for item in input().split()]
		ok = False
		for item in line[1:]:
			if is_taken[item]:
				continue
			else:
				is_taken[item] = True
				ok = True
				break
		if not ok:
			free = i
	if free is not None:
		print('IMPROVE')
		index = is_taken.index(0)
		print(free + 1, index + 1)
	else:
		print('OPTIMAL')


for _ in range(int(input())):
	n = int(input())
	l = []
	k = {}
	left = []
	for i in range(n):
		(length, *temp) = list(map(int, input().split()))
		l.append(temp)
		k[i + 1] = 1
	for i in range(n):
		for j in l[i]:
			if k[j] == 1:
				k[j] = 0
				break
		else:
			left.append(i + 1)
	if len(left) >= 1:
		print('IMPROVE')
		for king in k:
			if k[king] == 1:
				print(left[0], king)
				break
	else:
		print('OPTIMAL')


from sys import stdin, stdout

def main():
	for _ in range(int(stdin.readline())):
		K = int(stdin.readline())
		avl = set([x for x in range(1, K + 1)])
		s = -1
		for i in range(K):
			arr = list(map(int, input().split()))
			j = 1
			while j < len(arr) and arr[j] not in avl:
				j += 1
			if j == len(arr):
				s = i
			else:
				avl.remove(arr[j])
		if s == -1:
			stdout.write('OPTIMAL\n')
		else:
			stdout.write('IMPROVE\n')
			stdout.write(str(s + 1) + ' ' + str(avl.pop()) + '\n')
main()


import itertools

def solve():
	nbCases = int(input())
	for _ in range(nbCases):
		n = int(input())
		daughter_lists = []
		for _ in range(n):
			l = list(map(int, input().split()))[1:]
			l.sort()
			daughter_lists.append([x - 1 for x in l])
		process(daughter_lists)

def process(daughter_lists):
	n = len(daughter_lists)
	isKingdomFree = [True] * n
	freeDaughter = None
	for i in range(n):
		freeKingdomIterator = filter(lambda kindgom: isKingdomFree[kindgom], daughter_lists[i])
		firstFree = next(freeKingdomIterator, None)
		if firstFree == None:
			freeDaughter = i
		else:
			isKingdomFree[firstFree] = False
	if freeDaughter == None:
		print('OPTIMAL')
	else:
		freeKingdomIterator = filter(lambda kindgom: isKingdomFree[kindgom], range(n))
		firstFree = next(freeKingdomIterator, None)
		print('IMPROVE')
		print(freeDaughter + 1, firstFree + 1)
solve()


data = input().rstrip().split()
k = int(data[0])

def find_min(arr, free):
	for a in arr:
		if free[a - 1] == 1:
			return a
	return None
for _ in range(k):
	daughter = None
	data = input().rstrip().split()
	n = int(data[0])
	ps = []
	for i in range(n):
		data = input().rstrip().split()
		u = int(data[0])
		d = [int(e) for e in data[1:]]
		ps.append(d)
	free = [1] * n
	for i in range(1, n + 1):
		a = find_min(ps[i - 1], free)
		if a is None:
			daughter = i
		else:
			free[a - 1] = 0
	if daughter is None:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for j in range(1, n + 1):
			if free[j - 1] == 1:
				break
		print(str(daughter) + ' ' + str(j))


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append([int(i) for i in input().split()][1:])
	st = set()
	cnt = []
	k = 0
	for i in a:
		k += 1
		le = len(st)
		for j in i:
			if j not in st:
				st.add(j)
				cnt.append(j)
				break
		if len(st) == le:
			z = k
	if len(st) == n:
		print('OPTIMAL')
		continue
	cnt.sort()
	minn = -1
	for i in range(len(cnt)):
		if cnt[i] != i + 1:
			minn = i + 1
			break
	if minn == -1:
		minn = n
	print('IMPROVE')
	print(z, minn)


import sys
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	f = [0 for i in range(n + 1)]
	l = []
	flag = 0
	for i in range(n):
		a = [int(x) for x in input().split()]
		a = a[1:]
		a.sort()
		p = 0
		for j in range(len(a)):
			if f[a[j]] == 0:
				f[a[j]] = 1
				p = 1
				break
		if p == 0:
			l.append(i)
	if f[1:].count(0) >= 1 and len(l) > 0:
		print('IMPROVE')
		print(l[0] + 1, f[1:].index(0) + 1)
	else:
		print('OPTIMAL')


def solve(n, g):
	taken_k = [0] * n
	taken_d = [0] * n
	for i in range(n):
		for pref in g[i]:
			if not taken_k[pref]:
				taken_k[pref] = 1
				taken_d[i] = 1
				break
	if 0 not in taken_k:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(taken_d.index(0) + 1, taken_k.index(0) + 1)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		g = [[] for _ in range(n)]
		for j in range(n):
			gt = [int(i) - 1 for i in input().split()][1:]
			g[j] = gt
		solve(n, g)
main()


import sys
import bisect as bi
import math
from collections import defaultdict as dd
from types import GeneratorType
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def inin():
	return int(input())

def msb(n):
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n |= n >> 32
	n |= n >> 64
	return n - (n >> 1)
for _ in range(inin()):
	n = inin()
	d = dd(list)
	vis = [0] * n
	maxMin = 0
	for i in range(n):
		d[i] += sorted(ain()[1:])
		f = 0
		for j in d[i]:
			if vis[j - 1] == 0:
				vis[j - 1] = 1
				f = 1
				break
		if f == 0:
			store = i + 1
	if vis.count(1) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(store, vis.index(0) + 1)

def msb(n):
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n |= n >> 32
	n |= n >> 64
	return n - (n >> 1)

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre

def kadane(A):
	maxSoFar = maxEndingHere = start = end = beg = 0
	for i in range(len(A)):
		maxEndingHere = maxEndingHere + A[i]
		if maxEndingHere < 0:
			maxEndingHere = 0
			beg = i + 1
		if maxSoFar < maxEndingHere:
			maxSoFar = maxEndingHere
			start = beg
			end = i
	return (maxSoFar, start, end)

def modFact(n, p):
	if n < 0:
		return 0
	if n >= p:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % p
	return result

def ncr(n, r, p):
	if n < r or n < 0:
		return 0
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	taken = [0] * n
	flag = -1
	for i in range(n):
		a = LI()
		d = 0
		for j in range(1, a[0] + 1):
			if taken[a[j] - 1] == 0:
				taken[a[j] - 1] = 1
				d = 1
				break
		if not d:
			flag = i
	if flag == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(n):
			if taken[i] == 0:
				print(flag + 1, i + 1)
				break


for _ in range(int(input())):
	n = int(input())
	f = set([i for i in range(n)])
	r = []
	for i in range(n):
		f1 = 0
		a = list(map(int, input().split()))
		if len(a) == 0:
			r.append(i)
		else:
			for j in a[1:]:
				if j - 1 in f:
					f1 = 1
					f.remove(j - 1)
					break
			if f1 == 0:
				r.append(i)
	if len(r) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(r[0] + 1, sorted(list(f))[0] + 1)


t = int(input())
number = 0
while number != t:
	n = int(input())
	princes = [0 for _ in range(n + 1)]
	(flag, otherFlag) = (0, 1)
	princes[0] = 1
	for i in range(n):
		x = list(map(int, input().split()))
		count = 1
		simpleInit = x[0] + 1
		while count != simpleInit:
			if princes[x[count]] == 0:
				princes[x[count]] = 1
				break
			count += 1
		if count == simpleInit:
			if otherFlag == 1:
				flag = i + 1
				otherFlag = 0
	if flag == 0:
		print('OPTIMAL')
	else:
		posicaoZero = princes.index(0)
		print('IMPROVE')
		print('%d %d' % (flag, posicaoZero))
	number += 1


import sys

def input():
	return sys.stdin.readline().strip()
import bisect
for _ in range(int(input())):
	N = int(input())
	mark = {}
	for i in range(1, N + 1):
		mark[i] = -1
	c = 1
	l = 0
	Not = []
	for i in range(N):
		l += 1
		m = 0
		A = list(map(int, input().split(' ')))
		for j in range(c, N + 1):
			if mark.get(j, 0) == -1:
				c = j
				break
		x = bisect.bisect_left(A[1:], c)
		if A[min(x + 1, len(A) - 1)] == c:
			mark[c] = 1
			m = 1
		else:
			for j in range(x + 1, len(A)):
				if mark.get(A[j], 0) == -1:
					mark[A[j]] = 1
					m = 1
					break
		if m == 0:
			Not.append(l)
	f = 0
	for (i, j) in mark.items():
		if j == -1:
			f = 1
			print('IMPROVE')
			print(Not[0], i)
			break
	if f == 0:
		print('OPTIMAL')


for t in range(int(input())):
	n = int(input())
	(d, l) = ({}, [])
	for i in range(1, n + 1):
		a = list(map(int, input().split()))
		f = 0
		for j in range(1, a[0] + 1):
			if a[j] not in d:
				d[a[j]] = 0
				f = 1
				break
		if f == 0:
			l.append(i)
	if len(l) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for j in range(1, n + 1):
			if j not in d:
				print(l[0], j)
				break


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	happy = [False for x in range(n)]
	daughter = -1
	for i in range(n):
		l = list(map(int, stdin.readline().split()))[1:]
		for j in l:
			if not happy[j - 1]:
				happy[j - 1] = True
				break
		else:
			daughter = i
	if daughter == -1:
		stdout.write('OPTIMAL\n')
	else:
		u = happy.index(False)
		stdout.write('IMPROVE\n' + str(daughter + 1) + ' ' + str(u + 1) + '\n')


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def ri():
	return int(input())

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

def solve():
	n = ri()
	taken = set()
	last_missed = -1
	missing_prince = 1
	for i in range(n):
		L = rl()
		for l in L[1:]:
			if l not in taken:
				taken.add(l)
				if l == missing_prince:
					while missing_prince in taken:
						missing_prince += 1
				break
		else:
			last_missed = i + 1
	if last_missed == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(last_missed, missing_prince)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


for _ in range(int(input())):
	n = int(input())
	k = {}
	q = {}
	for i in range(1, n + 1):
		k[i] = 0
		q[i] = 0
	f = 0
	l1 = []
	for j in range(n):
		l = list(map(int, input().split()))
		l1.append(l[1:])
	for i in range(n):
		l = l1[i]
		for j in l:
			if k[j] == 0:
				k[j] = i + 1
				q[i + 1] = j
				break
	for (i, j) in k.items():
		if j == 0:
			p = i
			break
	for (i, j) in q.items():
		if j == 0:
			print('IMPROVE')
			print(i, p)
			f = 1
			break
	if f == 0:
		print('OPTIMAL')


from sys import stdin
t = int(stdin.readline().rstrip())
for _ in range(t):
	n = int(stdin.readline().rstrip())
	p = [i for i in range(n + 1)]
	q = [i for i in range(n + 1)]
	d = 1
	while n:
		l = list(map(int, stdin.readline().rstrip().split(' ')))
		for i in range(1, l[0] + 1):
			if p[l[i]] != 0:
				p[l[i]] = 0
				q[d] = 0
				break
		d = d + 1
		n -= 1
	if sum(p) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in q:
			if i != 0:
				print(i, end=' ')
				break
		for j in p:
			if j != 0:
				print(j)
				break


import sys
import os
from io import IOBase, BytesIO
import math
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	t = int(sin())
	for _ in range(t):
		n = int(sin())
		lst = []
		check = []
		for i in range(n):
			tmp = ain()
			k = tmp.pop(0)
			lst.append(tmp)
			check.append(-1)
		for i in range(n):
			prince = lst[i]
			for value in prince:
				if check[value - 1] == -1:
					check[value - 1] = i + 1
					break
		flag = 0
		d = -1
		p = -1
		for i in range(n):
			if check[i] == -1:
				p = i + 1
				for j in range(1, n + 1):
					if j not in check:
						d = j
						break
				flag = 1
				break
		if flag == 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(d, p)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t:
	n = int(input())
	a = []
	taken = set()
	improve = False
	un = None
	for i in range(1, n + 1):
		line = input().split()
		b = set([int(x) for x in line[1:]])
		m = None
		for x in b:
			if x not in taken:
				if m == None or x < m:
					m = x
		if m != None:
			taken.add(m)
		else:
			un = i
	if un != None:
		print('IMPROVE')
		for i in range(1, n + 1):
			if i not in taken:
				print(un, i)
				break
	else:
		print('OPTIMAL')
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	choices = []
	left = []
	princes = [False] * (n + 1)
	for p in range(1, n + 1):
		options = tuple(map(int, input().split()))
		found = False
		if options == 0:
			pass
		else:
			for i in range(1, options[0] + 1):
				if not princes[options[i]]:
					princes[options[i]] = True
					found = True
					break
		if not found:
			left.append(p)
	if not left:
		print('OPTIMAL')
		continue
	print('IMPROVE')
	for i in range(1, n + 1):
		if not princes[i]:
			print(left[0], i)
			break


T = int(input())
for lp in range(T):
	N = int(input())
	L = [0] * N
	princess_check = 0
	count = 0
	for j in range(N):
		stat = 0
		p = list(map(int, input().split()))
		p = p[1:]
		for i in p:
			if L[i - 1] == 0:
				L[i - 1] = 1
				count += 1
				stat = 1
				break
		if stat == 0:
			princess_check = j + 1
	if count == N:
		print('OPTIMAL')
	elif count < N:
		c = 0
		for i in range(N):
			if L[i] == 0:
				c = i + 1
				break
		print('IMPROVE')
		print(str(princess_check) + ' ' + str(c))


t = int(input())
while t:
	t -= 1
	n = int(input())
	all_lists = []
	for i in range(n):
		tmp = [int(i) for i in input().split()]
		if tmp[0] > 0:
			all_lists.append(tmp[1:])
		else:
			all_lists.append([])
	visited = [False for i in range(n + 1)]
	optimal = 1
	idx_q = -1
	idx_k = -1
	for (j, i) in enumerate(all_lists):
		flag = 0
		for each_kingdom in i:
			if visited[each_kingdom] == False:
				visited[each_kingdom] = True
				flag = 1
				break
		if flag:
			continue
		else:
			optimal = 0
			idx_q = j
	for (j, i) in enumerate(visited[1:]):
		if i == False:
			idx_k = j
			break
	if optimal:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(idx_q + 1, idx_k + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	c = []
	b = [0] * (n + 1)
	for __ in range(n):
		p = 1
		a = list(map(int, input().split()))
		for i in range(1, len(a)):
			if b[a[i]] == 0:
				b[a[i]] = 1
				p = 0
				break
		if p == 1:
			a[0] = __ + 1
			c = a
	if len(c) == 0:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in range(1, len(b)):
			if b[i] == 0:
				print(c[0], i)
				break


from sys import stdin, gettrace

def input():
	return stdin.buffer.readline()

def main():

	def solve():
		n = int(input())
		avail = [False] + [True] * n
		optimal = True
		for i in range(1, n + 1):
			dd = [int(a) for a in input().split()]
			for d in dd[1:]:
				if avail[d]:
					avail[d] = False
					break
			else:
				optimal = False
				wife = i
		if optimal:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(wife, avail.index(True))
	q = int(input())
	for _ in range(q):
		solve()
main()


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	list_married = [False for _ in range(n)]
	princess = -1
	for i in range(n):
		list_ = [int(x) - 1 for x in stdin.readline().split()][1:]
		for item in list_:
			if not list_married[item]:
				list_married[item] = True
				break
		else:
			princess = i
	if princess != -1:
		prince = list_married.index(False)
		stdout.write('IMPROVE\n' + str(princess + 1) + ' ' + str(prince + 1) + '\n')
	else:
		stdout.write('OPTIMAL\n')


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	k = []
	nok = []
	for i in range(n):
		a = input().split()
		if a == ['0']:
			nok.append(i + 1)
		l.append(a[1:])
		k.append(0)
	for i in range(n):
		for j in range(len(l[i])):
			if int(l[i][j]) > 0:
				if k[int(l[i][j]) - 1] == 0:
					k[int(l[i][j]) - 1] = 1
					break
				if k[int(l[i][j]) - 1] != 0 and j == len(l[i]) - 1:
					nok.append(i + 1)
	if k.count(0) == 0:
		print('OPTIMAL')
	else:
		ans = 0
		for i in range(n):
			if k[i] == 0:
				ans = i + 1
				break
		print('IMPROVE')
		print(nok[0], ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	n = int(input())
	gs = []
	used = [0] * n
	maybe = -1
	for i in range(n):
		(k, *gs) = map(lambda x: int(x) - 1, input().split())
		if all((used[j] for j in gs)):
			maybe = i
		else:
			for j in gs:
				if not used[j]:
					used[j] = 1
					break
	if maybe == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		target = used.index(0)
		print(maybe + 1, target + 1)
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	opt = [0] * (n + 1)
	bri = gro = 0
	for i in range(n):
		tem = sorted(list(map(int, input().split()))[1:])
		c = 0
		for j in tem:
			if opt[j] == 0:
				opt[j] = 1
				c = 1
				break
		if c == 0:
			bri = i + 1
	for i in range(1, n + 1):
		if opt[i] == 0:
			gro = i
	if sum(opt) == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(bri, gro)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	d = defaultdict(int)
	count = 0
	dau = [0] * n
	pr = []
	for i in range(n):
		k = list(map(int, input().split()))
		for j in range(k[0]):
			if d[k[j + 1]] == 0:
				d[k[j + 1]] = i + 1
				count += 1
				dau[i] += 1
				pr.append(k[j + 1])
				break
	if count == n:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		j = -1
		for i in range(n):
			if dau[i] == 0:
				j = i + 1
				break
		jj = -1
		for i in range(n):
			if d[i + 1] == 0:
				jj = i + 1
		print(j, jj)


from collections import defaultdict

def solve(n, d):
	(picked_daug, picked_king) = ([0] * (n + 1), [0] * (n + 1))
	for i in range(1, n + 1):
		size = d[i][0]
		for j in range(1, size + 1):
			prince = d[i][j]
			if picked_king[prince] == 0:
				picked_king[prince] = 1
				picked_daug[i] = 1
				break
	npd = npp = 0
	for i in range(1, n + 1):
		if picked_daug[i] == 0:
			npd = i
			break
	if npd != 0:
		for i in range(1, n + 1):
			if picked_king[i] == 0:
				npp = i
				break
		return ('IMPROVE', [npd, npp])
	else:
		return ('OPTIMAL', None)
t = int(input())
for _ in range(t):
	n = int(input())
	daughter = defaultdict(list)
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		daughter[i] = l
	(verdict, ans) = solve(n, daughter)
	if verdict == 'IMPROVE':
		print(verdict)
		print(*ans, sep=' ')
	else:
		print(verdict)


t = int(input())
while t != 0:
	n = int(input())
	list2 = list()
	list3 = list()
	for i in range(n):
		list2.append(0)
	for i in range(n):
		list3.append(0)
	for i in range(n):
		list1 = list(map(int, input().split()))
		p = list1.pop(0)
		if len(list1) == 0:
			mini = 0
		else:
			mini = 100000007
		f = 0
		for j in range(p):
			if mini >= list1[j] and list2[list1[j] - 1] == 0:
				mini = list1[j]
				f = 1
		if f == 1:
			list2[mini - 1] = -1
			list3[i] = -1
	(flag2, flag3) = (0, 0)
	(ans2, ans3) = (0, 0)
	for i in range(n):
		if flag2 == 0 and list3[i] == 0:
			ans2 = i + 1
			flag2 = 1
		if flag3 == 0 and list2[i] == 0:
			ans3 = i + 1
			flag3 = 1
		if flag2 == 1 and flag3 == 1:
			break
	if flag3 == 1 and flag2 == 1:
		print('IMPROVE')
		print(ans2, ans3)
	else:
		print('OPTIMAL')
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	mar = set()
	flag = 0
	king = set([i for i in range(1, n + 1)])
	for i in range(n):
		flag = 0
		a = list(map(int, input().split()))
		for j in a[1:]:
			if j not in mar:
				mar.add(j)
				king.remove(j)
				flag = 1
				break
		if flag == 0:
			pos = i + 1
	if len(king) != 0:
		print('IMPROVE')
		for i in king:
			print(pos, i)
			break
	else:
		print('OPTIMAL')


t = int(input())
for _ in range(t):
	n = int(input())
	fin = False
	king = [0] * n
	ind = -1
	for p in range(n):
		d = list(map(int, input().split()))
		if d[0] != 0:
			tf = False
			for i in range(1, len(d)):
				if king[d[i] - 1] == 0:
					king[d[i] - 1] = 1
					tf = True
					break
			if tf:
				pass
			else:
				ind = p + 1
		else:
			ind = p + 1
	for i in range(n):
		if king[i] == 0:
			break
	if ind != -1:
		print('IMPROVE')
		print(ind, i + 1)
	else:
		print('OPTIMAL')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	dict = {}
	temp = 0
	left_list = []
	for i in range(1, n + 1):
		dict[i] = 0
	for i in range(n):
		list = [int(x) for x in stdin.readline().split()]
		list = list[1:]
		min = 9999999
		for j in list:
			if dict[j] == 0:
				if j < min:
					min = j
		if min != 9999999:
			dict[min] = 1
		else:
			left_list.append(i + 1)
			temp = 1
	if temp == 0:
		stdout.write('OPTIMAL' + '\n')
		continue
	stdout.write('IMPROVE' + '\n')
	for i in dict:
		if dict[i] == 0:
			temp = i
			break
	stdout.write(str(left_list[0]) + ' ' + str(temp) + '\n')


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	b = [False for i in range(n)]
	g = None
	for gidx in range(n):
		a = [int(x) - 1 for x in stdin.readline().split()]
		for bidx in a[1:]:
			if not b[bidx]:
				b[bidx] = True
				break
		else:
			g = gidx
	if g is None:
		stdout.write('OPTIMAL\n')
	else:
		stdout.write('IMPROVE\n')
		stdout.write(str(g + 1) + ' ' + str(b.index(False) + 1) + '\n')


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		n = int(input())
		marry = {num: False for num in range(1, n + 1)}
		no_marry_idx = -1
		for idx in range(n):
			arr = list(map(int, input().split()))
			k = arr.pop(0)
			is_marry = False
			for p_idx in arr:
				if marry.get(p_idx) is False:
					marry[p_idx] = True
					is_marry = True
					break
			if not is_marry and no_marry_idx == -1:
				no_marry_idx = idx
		if no_marry_idx == -1:
			print('OPTIMAL')
			continue
		is_break = False
		for (k, v) in marry.items():
			if not v:
				print('IMPROVE')
				print(no_marry_idx + 1, k)
				is_break = True
				break
		if not is_break:
			print('OPTIMAL')
main()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	d = {}
	unm_d = []
	for i in range(n):
		l = list(map(int, stdin.readline().rstrip().split()))
		k = l[0]
		chk = False
		for j in range(1, k + 1):
			if l[j] not in d:
				d[l[j]] = True
				chk = True
				break
		if not chk:
			unm_d.append(i)
	if len(unm_d) == 0:
		print('OPTIMAL')
	else:
		for j in range(1, n + 1):
			if j not in d:
				ans = j
				break
		print('IMPROVE')
		print(unm_d[0] + 1, ans)


for x in range(int(input())):
	n = int(input())
	boyscheck = list((False for u in range(n)))
	girscheck = boyscheck.copy()
	t2 = []
	for y in range(n):
		t2.append(input())
	for y in range(n):
		temp = list(map(int, t2[y].split(' ')))
		temp.pop(0)
		for i in temp:
			if boyscheck[i - 1] == False and girscheck[y] == False:
				boyscheck[i - 1] = True
				girscheck[y] = True
	if False in girscheck:
		print('IMPROVE')
		print(girscheck.index(False) + 1, ' ', boyscheck.index(False) + 1, sep='')
	else:
		print('OPTIMAL')


for i in range(int(input())):
	n = int(input())
	if n == 1:
		if input() == '0':
			print('IMPROVE')
			print('1 1')
		else:
			print('OPTIMAL')
		continue
	d = [sorted([int(i) for i in input().split()[1:]]) for i in range(n)]
	p = set([i + 1 for i in range(n)])
	pr = set([i + 1 for i in range(n)])
	np = 0
	for i in range(n):
		for c in d[i]:
			if c in p:
				p.remove(c)
				np += 1
				pr.remove(i + 1)
				break
	if np == n:
		print('OPTIMAL')
		continue
	else:
		print('IMPROVE')
		print(pr.pop(), p.pop())


def solve():
	n = int(input())
	free_princess = None
	free_princes = [True] * n
	for i in range(n):
		married = False
		for wanted_prince in map(int, input().split()[1:]):
			if free_princes[wanted_prince - 1]:
				married = True
				free_princes[wanted_prince - 1] = False
				break
		if not married:
			free_princess = i + 1
	if not free_princess:
		return None
	else:
		free_prince = free_princes.index(True) + 1
		return (free_princess, free_prince)
for i in range(int(input())):
	result = solve()
	if result:
		print('IMPROVE')
		print(*result)
	else:
		print('OPTIMAL')


T = int(input())
while T > 0:
	n = int(input())
	arr = []
	g = [0] * n
	k = [0] * n
	for x in range(n):
		arr = map(int, input().split())
		arr = list(arr)
		for y in range(1, len(arr)):
			if k[arr[y] - 1] == 0:
				k[arr[y] - 1] = 1
				g[x] = 1
				break
	a = -1
	b = -1
	for x in range(n):
		if g[x] == 0:
			a = x + 1
		if k[x] == 0:
			b = x + 1
	if a == -1 and b == -1:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		print(a, b)
	T -= 1


for _ in range(int(input())):
	n = int(input())
	used = [False for i in range(n + 1)]
	used[0] = True
	v = 0
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		for j in l[1:]:
			if not used[j]:
				used[j] = True
				break
		else:
			v = i
	if v == 0:
		print('OPTIMAL')
	else:
		u = used.index(False)
		print('IMPROVE')
		print(v, u)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		dau = []
		d = {}
		for i in range(1, n + 1):
			d[i] = 0
		for i in range(n):
			x = list(map(int, input().split()))
			if x[0] == 0:
				dau.append([])
			else:
				dau.append(x[1:])
				for y in x[1:]:
					d[y] += 1
		vis = set([i for i in range(1, n + 1)])
		f = False
		ns = []
		printed = False
		for (i, x) in enumerate(dau):
			f = False
			cont = True
			for y in x:
				d[y] -= 1
				if y in vis and cont:
					f = True
					vis.remove(y)
					cont = False
			if not f:
				ns.append(i + 1)
		if len(ns) == 0:
			print('OPTIMAL')
		else:
			print('IMPROVE')
			print(ns[0], list(vis)[0])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for i in range(int(input())):
	n = int(input())
	a = []
	d = {}
	c = []
	for i in range(n):
		d[i + 1] = 0
	for i in range(n):
		a.append([])
		lst = list(map(int, input().split()))
		lst = lst[1:]
		st = False
		for j in lst:
			if d[j] == 0:
				st = True
				d[j] = 1
				break
		if not st:
			c.append(i + 1)
	if not c:
		print('OPTIMAL')
	else:
		print('IMPROVE')
		for i in d:
			if d[i] == 0:
				print(str(c.pop(0)) + ' ' + str(i))
				break


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = [False for i in range(n)]
	v = -1
	for i in range(n):
		a = list(map(int, stdin.readline().split()))[1:]
		for j in a:
			if not arr[j - 1]:
				arr[j - 1] = True
				break
		else:
			v = i
	if v == -1:
		stdout.write('OPTIMAL\n')
	else:
		u = arr.index(False)
		stdout.write('IMPROVE\n' + str(v + 1) + ' ' + str(u + 1) + '\n')