#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int T,n,m,x,ans;
int vis[100001];
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		memset(vis,0,sizeof(vis));
		scanf("%d",&n);
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			bool bj=0;
			scanf("%d",&m);
			for(int j=1;j<=m;j++)
			{
				scanf("%d",&x);
				if(!vis[x]&&!bj)
				{
					vis[x]++;
					bj=1;
				}
			}
			if(!bj) ans=i;
		}
		if(ans)
		{
			printf("IMPROVE\n");
			for(int i=1;i<=n;i++)
			    if(!vis[i])
			    {
			    	printf("%d %d\n",ans,i);
			    	break;
				}
		}
		else printf("OPTIMAL\n");
	}
	return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    cin>>t;
  A:  while(t--)
     {

         vector<int>v[siz];

        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            bool Flag=false;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                v[k].push_back(x);
                if(!Flag)
                {
                    if(!Guy[x])
                    {
                        Girl[i+1]=true;
                        Guy[x]=true;
                        Flag=true;
                    }
                }
            }

        }
       int Gi=-1,Gu=-1;
       for(int i=0;i<n;++i)
       {
           if(!Girl[i+1])
           {
               Gi=i+1;
               break;
           }
       }
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Gi==-1){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}

       for(int i=0;i<n;++i)Girl[i]=Guy[i]=false;
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    cin>>t;
  A:  while(t--)
     {
         memset(Girl,false,sizeof(Girl));
         memset(Guy,false,sizeof(Guy));
         vector<int>v[siz];

        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                v[k].push_back(x);
            }
            for(int j=0;j<v[k].size();++j)
            {
                int Temp=v[k][j];
                if(!Guy[Temp])
                {
                    Girl[i+1]=true;
                    Guy[Temp]=true;

                    break;
                }
            }
        }
       int Gi=-1,Gu=-1;
       for(int i=0;i<n;++i)
       {
           if(!Girl[i+1])
           {
               Gi=i+1;
               break;
           }
       }
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Gi==-1){cout<<"OPTIMAL"<<endl;goto A;}
       cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    cin>>t;
  A:  while(t--)
     {
        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            bool Flag=false;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                if(!Flag)
                {
                    if(!Guy[x])
                    {
                        Girl[i+1]=true;
                        Guy[x]=true;
                        Flag=true;
                    }
                }
            }

        }
       int Gi=-1,Gu=-1;
       for(int i=0;i<n;++i)
       {
           if(!Girl[i+1])
           {
               Gi=i+1;
               break;
           }
       }
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Gi==-1){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}

       for(int i=0;i<n;++i)Girl[i]=Guy[i]=false;
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    cin>>t;
  A:  while(t--)
     {

         vector<int>v[siz];

        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                v[k].push_back(x);
            }
            for(int j=0;j<v[k].size();++j)
            {
                int Temp=v[k][j];
                if(!Guy[Temp])
                {
                    Girl[i+1]=true;
                    Guy[Temp]=true;

                    break;
                }
            }
        }
       int Gi=-1,Gu=-1;
       for(int i=0;i<n;++i)
       {
           if(!Girl[i+1])
           {
               Gi=i+1;
               break;
           }
       }
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Gi==-1){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}

       for(int i=0;i<n;++i)Girl[i]=Guy[i]=false;
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Guy[siz];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

      cin>>t;
  A:  while(t--)
     {
         memset(Guy,false,sizeof(Guy));
        cin>>n;int Marr=0,Gi=0;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            bool Flag=false;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                if(!Flag)
                {
                    if(!Guy[x])
                    {
                        Marr++;
                        Guy[x]=true;
                        Flag=true;
                    }
                }
            }
           if(!Flag){Gi=i+1;}
        }
       int Gu=-1;
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Gi==0){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    cin>>t;
  A:  while(t--)
     {
        cin>>n;int Marr=0,Gi=0;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            bool Flag=false;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                if(!Flag)
                {
                    if(!Guy[x])
                    {
                        Girl[i+1]=true;
                        Guy[x]=true;
                        Flag=true;
                    }
                }
            }
           if(!Flag)Gi=i+1;
        }
       int Gu=-1;
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Marr==n){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}

       for(int i=0;i<n;++i)Girl[i]=Guy[i]=false;
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    cin>>t;
  A:  while(t--)
     {
        cin>>n;int Marr=0;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            bool Flag=false;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                if(!Flag)
                {
                    if(!Guy[x])
                    {
                        Girl[i+1]=true;
                        Guy[x]=true;
                        Flag=true;
                    }
                }
            }
           if(!Flag)Marr=i+1;
        }
       int Gu=-1;
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Marr==n){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}

       for(int i=0;i<n;++i)Girl[i]=Guy[i]=false;
     }
    return 0;
}


/* Author : the_compiler*/

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int siz=1e5+9;
const int MOD=1e9+7;

int t;
int n,k;
bool Girl[siz],Guy[siz];
int main()
{
    cin>>t;
  A:  while(t--)
     {

         vector<int>v[siz];

        cin>>n;
        for(int i=0;i<n;++i)
        {
            cin>>k;
            bool Flag=false;
            for(int j=0;j<k;++j)
            {
                int x;cin>>x;
                v[k].push_back(x);
                if(!Flag)
                {
                    if(!Guy[x])
                    {
                        Girl[i+1]=true;
                        Guy[x]=true;
                        Flag=true;
                    }
                }
            }

        }
       int Gi=-1,Gu=-1;
       for(int i=0;i<n;++i)
       {
           if(!Girl[i+1])
           {
               Gi=i+1;
               break;
           }
       }
       for(int i=1;i<=n;++i)
       {
           if(!Guy[i])
           {
               Gu=i;
               break;
           }
       }
       if(Gi==-1){cout<<"OPTIMAL"<<endl;}
       else{cout<<"IMPROVE"<<endl;
       cout<<Gi<<" "<<Gu<<endl;}

       for(int i=0;i<n;++i)Girl[i]=Guy[i]=false;
     }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int p=0;
        vector <bool> used(n,false);
        vector <bool> used2(n,false);
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            vector <int> a(k);
            for(int j=0;j<k;j++)
                cin>>a[j];
            bool good=false;
            for(int j=0;j<k;j++){
                if(good==false && !used[a[j]-1]){
                    used[i]=true;
                    used2[a[j]-1]=true;
                    good=true;
                    p++;
                }
            }
        }
        if(p==n){
            cout<<"OPTIMAL"<<endl;
        }
        else{
            cout<<"IMPROVE"<<endl;
            int p1,p2;
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p1=i;
                    break;
                }
            }
            for(int i=n-1;i>=0;i--){
                if(!used2[i]){
                    p2=i;
                    break;
                }
            }
            cout<<p1+1<<' '<<p2+1<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int p=0;
        vector <bool> used(n,false);
        vector <bool> used2(n,false);
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            bool good=false;
            while(k--){
                int a;
                cin>>a;
                if(good==false && !used[a-1]){
                    used[i]=true;
                    used2[a-1]=true;
                    good=true;
                    p++;
                }
            }
        }
        if(p==n){
            cout<<"OPTIMAL"<<endl;
        }
        else{
            cout<<"IMPROVE"<<endl;
            int p1,p2;
            for(int i=0;i<n;i++){
                if(!used[i]){
                    p1=i;
                    break;
                }
            }
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p2=i;
                    break;
                }
            }
            cout<<p1+1<<' '<<p2+1<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int p=0;
        vector <bool> used(n,false);
        vector <bool> used2(n,false);
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            vector <int> a(k);
            for(int j=0;j<k;j++)
                cin>>a[j];
            for(int j=0;j<k;j++){
                if(!used2[a[j]-1]){
                    used[i]=true;
                    used2[a[j]-1]=true;
                    p++;
                    break;
                }
            }
        }
        if(p==n){
            cout<<"OPTIMAL"<<endl;
        }
        else{
            cout<<"IMPROVE"<<endl;
            int p1,p2;
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p1=i;
                    break;
                }
            }
            for(int i=n-1;i>=0;i--){
                if(!used2[i]){
                    p2=i;
                    break;
                }
            }
            cout<<p1+1<<' '<<p2+1<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int p=0;
        vector <bool> used(n,false);
        vector <bool> used2(n,false);
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            bool good=false;
            while(k--){
                int a;
                cin>>a;
                if(good==false && !used[a-1]){
                    used[i]=true;
                    used2[a-1]=true;
                    good=true;
                    p++;
                }
            }
        }
        if(p==n){
            cout<<"OPTIMAL"<<endl;
        }
        else{
            cout<<"IMPROVE"<<endl;
            int p1,p2;
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p1=i;
                    break;
                }
            }
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p2=i;
                    break;
                }
            }
            cout<<p1+1<<' '<<p2+1<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int p=0;
        vector <bool> used(n,false);
        vector <bool> used2(n,false);
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            vector <int> a(k);
            for(int j=0;j<k;j++)
                cin>>a[j];
            sort(a.begin(),a.end());
            bool good=false;
            for(int j=0;j<k;j++){
                if(good==false && !used[a[j]-1]){
                    used[i]=true;
                    used2[a[j]-1]=true;
                    good=true;
                    p++;
                }
            }
        }
        if(p==n){
            cout<<"OPTIMAL"<<endl;
        }
        else{
            cout<<"IMPROVE"<<endl;
            int p1,p2;
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p1=i;
                    break;
                }
            }
            for(int i=n-1;i>=0;i--){
                if(!used2[i]){
                    p2=i;
                    break;
                }
            }
            cout<<p1+1<<' '<<p2+1<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int p=0;
        vector <bool> used(n,false);
        vector <bool> used2(n,false);
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            bool good=false;
            while(k--){
                int a;
                cin>>a;
                if(good==false && !used[a-1]){
                    used[i]=true;
                    used2[a-1]=true;
                    good=true;
                    p++;
                }
            }
        }
        if(p==n){
            cout<<"OPTIMAL"<<endl;
        }
        else{
            cout<<"IMPROVE"<<endl;
            int p1,p2;
            for(int i=n-1;i>=0;i--){
                if(!used[i]){
                    p1=i;
                    break;
                }
            }
            for(int i=n-1;i>=0;i--){
                if(!used2[i]){
                    p2=i;
                    break;
                }
            }
            cout<<p1+1<<' '<<p2+1<<endl;
        }
    }
    return 0;
}


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

int t, tmp;

void solve() {
    int n, k;
    vector<int> a[200011];
    int prince[200011];
    cin >> n; prince[n] = 0;
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp-1);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }

    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


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

long long int t, tmp;

void solve() {
    int n, k;
    vector<int> a[20011];
    int prince[20011];
    cin >> n; prince[n] = 0;
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }

    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


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

long long int t, tmp;

void solve() {
    int n, k;
    vector<int> a[20011];
    int prince[20011];
    cin >> n; prince[n] = 0;
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp-1);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }
    //d
    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


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

long long int t, tmp;
vector<int> a[200011];
int prince[200011];

void solve() {
    int n, k;
    cin >> n;
    for (int i = 0; i <= n; i++) prince[i] = 0, a[i].clear();
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp-1);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }

    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


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

long long int t, tmp;

void solve() {
    int n, k;
    vector<int> a[20011];
    int prince[20011];
    cin >> n; prince[n] = 0;
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp-1);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }

    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


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

long long int t, tmp;

void solve() {
    int n, k;
    vector<int> a[200011];
    int prince[200011];
    cin >> n; prince[n] = 0;
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp-1);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }

    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


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

long long int t, tmp;

void solve() {
    int n, k;
    vector<int> a[20011];
    int prince[20011];
    cin >> n; prince[n] = 0;
    for (int i = 0; i < n; i++) {
        prince[i] = 0;
        cin >> k;
        for (int j = 0; j < k; j++) cin >> tmp, a[i].push_back(tmp-1);
    }

    int marry = 0, bachqueen = -1, bachking = -1;
    for (int i = 0; i < n; i++) {
        int kuwari = 1;
        for (auto banda: a[i]) {
            if (prince[banda] == 0) {
                marry++;
                prince[banda] = 1;
                kuwari = 0;
                break;
            }
        }
        if (kuwari == 1) bachqueen = i;
    }

    if (marry == n) {
        cout << "OPTIMAL\n";
    } else {
        cout << "IMPROVE\n";
        for (int i = 0; i < n; i++) if (prince[i] == 0) {bachking = i;break;}
        cout << bachqueen+1 << " " << bachking+1 << "\n";
    }
    return;
}

int main() {
    /*ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);*/
    cin >> t;
    while (t--) {
        solve();
        //break;
    }

	return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define db double
#define str string
#define fi first
#define se second
#define pu push
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pbb pop_back
#define pq priority_queue
#define umap unordered_map
#define pll pair<ll,ll>    /*new*/
#define VI vector<ll>		/*new*/
#define VP vector<pll >
#define bg(x) ((x.begin()))
#define ed(x) ((x.end()))
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(ll i=0;i<x;i++)
#define repp(i,x,y) for(ll i=x;i<y;i++)
#define hashcode(x,y,z) ((x+1)*1000000+(y+1)*1000+(z+1)) /*always modify*/
#define lson(x) (x << 1)
#define rson(x) ((x << 1) | 1)
#define lowbit(x) (x&(-x))
#define debug(x) cout << "{-- " << #x << " = " << x << " --}\n";
#define sz(x) ((ll)x.size())
#define have(x,y) ((x ^ y) == (x - y))
#define mem(x) (memset(x,0,sizeof(x)))
#define fil(x,val) (fill(bg(x),ed(x),val))
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define BUG cout << "Here" << endl;

const ll inf = 1e9+7;
const ll mod = 1e9+7;
map<int,int>::iterator it;

ll read() { ll x;scanf("%lld",&x);return x;}
str c2s(char c){string re="0";re[0]=c;return re;}
ll printv(vector<ll>V){ cout << V.size() << ": "; rep(i,V.size()) cout << V[i] << " "; puts("");}
ll gcd(ll x,ll y){while(x%y){ll t=x%y;x=y;y=t;}return y;}
ll readv(vector<ll>&V){rep(i,sz(V)) V[i] = read();}
bool isprime(ll x){for(ll i=2;i*i<=x;i++) if(x%i==0) return false;return true;}
/*
	always use:
	ll n = read(); VI V(n); readv(V);
*/
/* ----------------- code begin ------------------- */
int main(){
	ll ca = read();
	rep(ci,ca){
		ll n = read();
		VI vis(n+1);
		VI v[105];
		repp(i,1,n+1){
			ll x = read();
			rep(j,x) v[i].pb(read());
		}
		bool change = false;
		repp(i,1,n+1){
			ll ok = false;
			rep(j,v[i].size()) {
				if(!vis[v[i][j]] && !ok) {vis[v[i][j]] = 1; ok = true;}
			}
			if(!ok){
				cout << "IMPROVE" << endl;
				cout << i << " ";
				repp(j,1,n+1) if(!vis[j]) {cout << j << endl;break;}
				change = true;
				break;
			}
		}
		if(!change) puts("OPTIMAL");
	}
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define db double
#define str string
#define fi first
#define se second
#define pu push
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pbb pop_back
#define pq priority_queue
#define umap unordered_map
#define pll pair<ll,ll>    /*new*/
#define VI vector<ll>		/*new*/
#define VP vector<pll >
#define bg(x) ((x.begin()))
#define ed(x) ((x.end()))
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(ll i=0;i<x;i++)
#define repp(i,x,y) for(ll i=x;i<y;i++)
#define hashcode(x,y,z) ((x+1)*1000000+(y+1)*1000+(z+1)) /*always modify*/
#define lson(x) (x << 1)
#define rson(x) ((x << 1) | 1)
#define lowbit(x) (x&(-x))
#define debug(x) cout << "{-- " << #x << " = " << x << " --}\n";
#define sz(x) ((ll)x.size())
#define have(x,y) ((x ^ y) == (x - y))
#define mem(x) (memset(x,0,sizeof(x)))
#define fil(x,val) (fill(bg(x),ed(x),val))
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define BUG cout << "Here" << endl;

const ll inf = 1e9+7;
const ll mod = 1e9+7;
map<int,int>::iterator it;

ll read() { ll x;scanf("%lld",&x);return x;}
str c2s(char c){string re="0";re[0]=c;return re;}
ll printv(vector<ll>V){ cout << V.size() << ": "; rep(i,V.size()) cout << V[i] << " "; puts("");}
ll gcd(ll x,ll y){while(x%y){ll t=x%y;x=y;y=t;}return y;}
ll readv(vector<ll>&V){rep(i,sz(V)) V[i] = read();}
bool isprime(ll x){for(ll i=2;i*i<=x;i++) if(x%i==0) return false;return true;}
/*
	always use:
	ll n = read(); VI V(n); readv(V);
*/
/* ----------------- code begin ------------------- */
VI v[100005];
int main(){
	ll ca = read();
	rep(ci,ca){
		ll n = read();
		for(ll i=1;i<=n;i++)
			v[i].clear();
		VI vis(n+1);
		repp(i,1,n+1){
			ll x = read();
			rep(j,x) v[i].pb(read());
		}
		bool change = false;
		ll la = 0;
		repp(i,1,n+1){
			ll ok = false;
			rep(j,v[i].size()) {
				if(!vis[v[i][j]] && !ok) {vis[v[i][j]] = 1; ok = true;break;}
			}
			if(!ok) {la = i;change = true;}
		}
		if(change){
			cout << "IMPROVE" << endl;
			cout << la << " ";
			repp(j,1,n+1) if(!vis[j]) {cout << j << endl;break;}
		}
		else puts("OPTIMAL");
	}
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define db double
#define str string
#define fi first
#define se second
#define pu push
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pbb pop_back
#define pq priority_queue
#define umap unordered_map
#define pll pair<ll,ll>    /*new*/
#define VI vector<ll>		/*new*/
#define VP vector<pll >
#define bg(x) ((x.begin()))
#define ed(x) ((x.end()))
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(ll i=0;i<x;i++)
#define repp(i,x,y) for(ll i=x;i<y;i++)
#define hashcode(x,y,z) ((x+1)*1000000+(y+1)*1000+(z+1)) /*always modify*/
#define lson(x) (x << 1)
#define rson(x) ((x << 1) | 1)
#define lowbit(x) (x&(-x))
#define debug(x) cout << "{-- " << #x << " = " << x << " --}\n";
#define sz(x) ((ll)x.size())
#define have(x,y) ((x ^ y) == (x - y))
#define mem(x) (memset(x,0,sizeof(x)))
#define fil(x,val) (fill(bg(x),ed(x),val))
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define BUG cout << "Here" << endl;

const ll inf = 1e9+7;
const ll mod = 1e9+7;
map<int,int>::iterator it;

ll read() { ll x;scanf("%lld",&x);return x;}
str c2s(char c){string re="0";re[0]=c;return re;}
ll printv(vector<ll>V){ cout << V.size() << ": "; rep(i,V.size()) cout << V[i] << " "; puts("");}
ll gcd(ll x,ll y){while(x%y){ll t=x%y;x=y;y=t;}return y;}
ll readv(vector<ll>&V){rep(i,sz(V)) V[i] = read();}
bool isprime(ll x){for(ll i=2;i*i<=x;i++) if(x%i==0) return false;return true;}
/*
	always use:
	ll n = read(); VI V(n); readv(V);
*/
/* ----------------- code begin ------------------- */
int main(){
	ll ca = read();
	rep(ci,ca){
		ll n = read();
		VI vis(n+1);
		VI v[100005];
		repp(i,1,n+1){
			ll x = read();
			rep(j,x) v[i].pb(read());
		}
		bool change = false;
		repp(i,1,n+1){
			ll ok = false;
			rep(j,v[i].size()) {
				if(!vis[v[i][j]] && !ok) {vis[v[i][j]] = 1; ok = true;}
			}
			if(!ok){
				cout << "IMPROVE" << endl;
				cout << i << " ";
				repp(j,1,n+1) if(!vis[j]) cout << j << endl;
				change = true;
				break;
			}
		}
		if(!change) puts("OPTIMAL");
	}
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define db double
#define str string
#define fi first
#define se second
#define pu push
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pbb pop_back
#define pq priority_queue
#define umap unordered_map
#define pll pair<ll,ll>    /*new*/
#define VI vector<ll>		/*new*/
#define VP vector<pll >
#define bg(x) ((x.begin()))
#define ed(x) ((x.end()))
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(ll i=0;i<x;i++)
#define repp(i,x,y) for(ll i=x;i<y;i++)
#define hashcode(x,y,z) ((x+1)*1000000+(y+1)*1000+(z+1)) /*always modify*/
#define lson(x) (x << 1)
#define rson(x) ((x << 1) | 1)
#define lowbit(x) (x&(-x))
#define debug(x) cout << "{-- " << #x << " = " << x << " --}\n";
#define sz(x) ((ll)x.size())
#define have(x,y) ((x ^ y) == (x - y))
#define mem(x) (memset(x,0,sizeof(x)))
#define fil(x,val) (fill(bg(x),ed(x),val))
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define BUG cout << "Here" << endl;

const ll inf = 1e9+7;
const ll mod = 1e9+7;
map<int,int>::iterator it;

ll read() { ll x;scanf("%lld",&x);return x;}
str c2s(char c){string re="0";re[0]=c;return re;}
ll printv(vector<ll>V){ cout << V.size() << ": "; rep(i,V.size()) cout << V[i] << " "; puts("");}
ll gcd(ll x,ll y){while(x%y){ll t=x%y;x=y;y=t;}return y;}
ll readv(vector<ll>&V){rep(i,sz(V)) V[i] = read();}
bool isprime(ll x){for(ll i=2;i*i<=x;i++) if(x%i==0) return false;return true;}
/*
	always use:
	ll n = read(); VI V(n); readv(V);
*/
/* ----------------- code begin ------------------- */
int main(){
	ll ca = read();
	VI v[100005];
	rep(ci,ca){
		ll n = read();
		for(int i=1;i<=n;i++)
			v[i].clear();
		VI vis(n+1);
		repp(i,1,n+1){
			ll x = read();
			rep(j,x) v[i].pb(read());
		}
		bool change = false;
		repp(i,1,n+1){
			ll ok = false;
			rep(j,v[i].size()) {
				if(!vis[v[i][j]] && !ok) {vis[v[i][j]] = 1; ok = true;}
			}
			if(!ok){
				cout << "IMPROVE" << endl;
				cout << i << " ";
				repp(j,1,n+1) if(!vis[j]) {cout << j << endl;break;}
				change = true;
				break;
			}
		}
		if(!change) puts("OPTIMAL");
	}
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define db double
#define str string
#define fi first
#define se second
#define pu push
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pbb pop_back
#define pq priority_queue
#define umap unordered_map
#define pll pair<ll,ll>    /*new*/
#define VI vector<ll>		/*new*/
#define VP vector<pll >
#define bg(x) ((x.begin()))
#define ed(x) ((x.end()))
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(ll i=0;i<x;i++)
#define repp(i,x,y) for(ll i=x;i<y;i++)
#define hashcode(x,y,z) ((x+1)*1000000+(y+1)*1000+(z+1)) /*always modify*/
#define lson(x) (x << 1)
#define rson(x) ((x << 1) | 1)
#define lowbit(x) (x&(-x))
#define debug(x) cout << "{-- " << #x << " = " << x << " --}\n";
#define sz(x) ((ll)x.size())
#define have(x,y) ((x ^ y) == (x - y))
#define mem(x) (memset(x,0,sizeof(x)))
#define fil(x,val) (fill(bg(x),ed(x),val))
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define BUG cout << "Here" << endl;

const ll inf = 1e9+7;
const ll mod = 1e9+7;
map<int,int>::iterator it;

ll read() { ll x;scanf("%lld",&x);return x;}
str c2s(char c){string re="0";re[0]=c;return re;}
ll printv(vector<ll>V){ cout << V.size() << ": "; rep(i,V.size()) cout << V[i] << " "; puts("");}
ll gcd(ll x,ll y){while(x%y){ll t=x%y;x=y;y=t;}return y;}
ll readv(vector<ll>&V){rep(i,sz(V)) V[i] = read();}
bool isprime(ll x){for(ll i=2;i*i<=x;i++) if(x%i==0) return false;return true;}
/*
	always use:
	ll n = read(); VI V(n); readv(V);
*/
/* ----------------- code begin ------------------- */
int main(){
	ll ca = read();
	rep(ci,ca){
		ll n = read();
		VI vis(n+1);
		VI v[100005];
		repp(i,1,n+1){
			ll x = read();
			rep(j,x) v[i].pb(read());
		}
		bool change = false;
		repp(i,1,n+1){
			ll ok = false;
			rep(j,v[i].size()) {
				if(!vis[v[i][j]] && !ok) {vis[v[i][j]] = 1; ok = true;}
			}
			if(!ok){
				cout << "IMPROVE" << endl;
				cout << i << " ";
				repp(j,1,n+1) if(!vis[j]) {cout << j << endl;break;}
				change = true;
				break;
			}
		}
		if(!change) puts("OPTIMAL");
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        unordered_map<int,vector<int> >mp;
        int n;
        cin>>n;
        int k;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            for(int j=0;j<k;j++)
            {
                int x;
                cin>>x;
                mp[i].push_back(x);
            }
        }
        bool marked[n+1] ={};
        // bool prin[n+1]={};
        if(mp.size()==0)
        {
            cout<<"IMPROVE"<<endl;
            cout<<1<< " " <<1<<endl;
            continue;
        }
        bool kingdom[n+1] ={};
        vector<int>princess ;
        bool flag=0;
        for(int i=1;i<=n;i++)
        {
            int j;
            for(j=0;j<mp[i].size();j++)
            {
                if(kingdom[mp[i][j]] == 0)
                {
                    kingdom[mp[i][j]]=true;
                    break;
                }
            }
            if(j==mp[i].size())
                princess.push_back(i);
        }
        for(int i = princess.size()-1;i>=0;i--)
        {
            for(int j=1;j<=n;j++)
            {
                if(kingdom[j] == 0)
                {
                    cout<<"IMPROVE"<<endl;
                    cout<<princess[i]<<" "<<j<<endl;
                    flag=1;
                    break;
                }
            }
                if(flag==1)
                    break;
        }
        if(!flag)
            cout<<"OPTIMAL"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        unordered_map<int,vector<int> >mp;
        int n;
        cin>>n;
        int k;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            for(int j=0;j<k;j++)
            {
                int x;
                cin>>x;
                mp[i].push_back(x);
            }
        }
        bool marked[n+1] ={};
        // bool prin[n+1]={};
        if(mp.size()==0)
        {
            cout<<"IMPROVE"<<endl;
            cout<<1<< " " <<1<<endl;
            continue;
        }
        bool kingdom[n+1] ={};
        vector<int>princess ;
        bool flag=0;
        for(int i=1;i<=n;i++)
        {
            int j;
            for(j=0;j<mp[i].size();j++)
            {
                if(kingdom[mp[i][j]] == 0)
                {
                    kingdom[mp[i][j]]=true;
                    break;
                }
            }
            if(j==mp[i].size())
                princess.push_back(i);
        }
        for(int i = princess.size()-1;i>=0;i--)
        {
            for(int j=1;j<=n;j++)
            {
                if(kingdom[j] == 0)
                {
                    cout<<"IMPROVE"<<endl;
                    cout<<princess[i]<<" "<<j<<endl;
                    flag=1;
                    break;
                }
            }
        }
        if(!flag)
            cout<<"OPTIMAL"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        unordered_map<int,vector<int> >mp;
        int n;
        cin>>n;
        int k;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            for(int j=0;j<k;j++)
            {
                int x;
                cin>>x;
                mp[i].push_back(x);
            }
        }
        bool marked[n+1] ={};
        // bool prin[n+1]={};
        if(mp.size()==0)
        {
            cout<<"IMPROVE"<<endl;
            cout<<1<< " " <<1<<endl;
            continue;
        }
        bool kingdom[n+1] ={};
        vector<int>princess ;
        bool flag=0;
        for(int i=1;i<=n;i++)
        {
            int j;
            for(j=0;j<mp[i].size();j++)
            {
                if(kingdom[mp[i][j]] == 0)
                {
                    kingdom[mp[i][j]]=true;
                    break;
                }
            }
            if(j==mp[i].size())
                princess.push_back(i);
        }
        for(int i = princess.size()-1;i>=0;i--)
        {
            for(int j=1;j<=n;j++)
            {
                if(kingdom[j] == 0)
                {
                    cout<<"IMPROVE"<<endl;
                    cout<<princess[i]<<" "<<j<<endl;
                    flag=1;
                    break;
                }
                if(flag==1)
                    break;
            }
        }
        if(!flag)
            cout<<"OPTIMAL"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        unordered_map<int,vector<int> >mp;
        int n;
        cin>>n;
        int k;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            for(int j=0;j<k;j++)
            {
                int x;
                cin>>x;
                mp[i].push_back(x);
            }
        }
        bool marked[n+1] ={};
        // bool prin[n+1]={};
        if(mp.size()==0)
        {
            cout<<"IMPROVE"<<endl;
            cout<<1<< " " <<1<<endl;
            continue;
        }
        bool kingdom[n+1] ={};
        int princess = 0;
        bool flag=0;
        for(int i=1;i<=n;i++)
        {
            int j;
            for(j=0;j<mp[i].size();j++)
            {
                if(kingdom[mp[i][j]] == 0)
                {
                    kingdom[mp[i][j]]=true;
                    break;
                }
            }
            if(j==mp[i].size())
            {
                princess=i;
                break;
            }
        }
        if(princess)
        {
            for(int i=1;i<=n;i++)
            {
                if(kingdom[i]==0)
                {

                    cout<<"IMPROVE"<<endl;
                    cout<<princess<<" "<<i<<endl;
                    flag=1;
                    break;
                }

            }
        }
        if(!flag)
            cout<<"OPTIMAL"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        map<int,vector<int> >mp;
        int n;
        cin>>n;
        int k;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            for(int j=0;j<k;j++)
            {
                int x;
                cin>>x;
                mp[i].push_back(x);
            }
        }
        bool marked[n+1] ={};
        bool prin[n+1]={};
        if(mp.size()==0)
        {
            cout<<"IMPROVE"<<endl;
            cout<<1<< " " <<1<<endl;
            continue;
        }
        for(auto i=mp.begin();i!=mp.end();i++)
        {
            int x = i->first;
            int s = i->second.size();
            for(int j=0;j<s;j++)
            {
                if(marked[i->second[j]] == 0)
                {
                    marked[i->second[j]] = 1;
                    prin[i->first]  = 1;
                    break;
                }
            }
        }
        bool flag=0;
        for(int i=n;i>=1;i--)
        {
            if(prin[i]!=1)
            {
                auto x = mp[i];
                int j = x.size();
                int l = x[j-1];
                for(int m = l;m <=n;m++)
                {
                    if(marked[m] == 0)
                    {
                        cout<<"IMPROVE"<<endl;
                        cout<<i<<" "<<m<<endl;
                        flag=1;
                        break;
                    }
                }
            }
        }
        if(flag==0)
            cout<<"OPTIMAL"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans;
main() {
    //freopen("INP.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> t;
    while(t--) {
        bool ok; ans = 0;
        cin >> n;
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            cin >> m;
            ok = false;
            while(m--){
                int x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans;
main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> t;
    while(t--) {
        bool ok; ans = 0;
        cin >> n;
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            cin >> m;
            ok = false;
            while(m--){
                int x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+5;
int a[N];
main() {
    //freopen("INP.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--) {
        bool ok = false;
        int n,ans=0; cin >> n;
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            int m; cin >> m;
            ok = false;
            while(m--){
                int x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans;
main() {
    //freopen("INP.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> t;
    while(t--) {
        bool ok; ans = 0;
        cin >> n;
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            cin >> m;
            ok = false;
            while(m--){
                int x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans,x;
main() {
   // freopen("INP.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    scanf("%d",&t);
    while(t--) {
        bool ok = false; ans = 0;
        scanf("%d",&n);
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            scanf("%d",&m);
            ok = false;
            while(m--){
                scanf("%d",&x);
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) printf("OPTIMAL");
        else {
            printf("IMPROVE\n");
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    printf("%d %d",ans,i);
                    break;
                }
        }
        printf("\n");
    }
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans,x;
main() {
   // freopen("INP.inp","r",stdin);
   // ios::sync_with_stdio(0); cin.tie(0);
    scanf("%d",&t);
    while(t--) {
        bool ok = false; ans = 0;
        scanf("%d",&n);
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            scanf("%d",&m);
            ok = false;
            while(m--){
                scanf("%d",&x);
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) printf("OPTIMAL");
        else {
            printf("IMPROVE\n");
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    printf("%d %d",ans,i);
                    break;
                }
        }
        printf("\n");
    }
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans;
main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> t;
    while(t--) {
        bool ok; ans = 0;
        cin >> n;
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            cin >> m;
            ok = false;
            while(m--){
                int x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5+5;
int a[N];
int t,m,n,ans,x;
main() {
    freopen("INP.inp","r",stdin);
   // ios::sync_with_stdio(0); cin.tie(0);
    scanf("%d",&t);
    while(t--) {
        bool ok = false; ans = 0;
        scanf("%d",&n);
        memset(a,0,sizeof(a));
        for(int i=1 ; i<=n ; i++) {
            scanf("%d",&m);
            ok = false;
            while(m--){
                scanf("%d",&x);
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) printf("OPTIMAL");
        else {
            printf("IMPROVE\n");
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    printf("%d %d",ans,i);
                    break;
                }
        }
        printf("\n");
    }
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5+5;
int a[N];
main() {
   // freopen("INP.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--) {
        bool ok = false;
        int n,ans=0; cin >> n;
        memset(a,0,sizeof(a));
        for(int i=0 ; i<n ; i++) {
            int m; cin >> m;
            ok = false;
            for(int j=1 ; j<=m ; j++) {
                int x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i+1;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(int i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;
const long long N = 1e5+5;
long long a[N];
long long t,m,n,ans,x;
main() {
    //freopen("INP.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    scanf("%lld",&t);
    while(t--) {
        bool ok; ans = 0;
        scanf("%lld",&n);
        memset(a,0,sizeof(a));
        for(long long i=1 ; i<=n ; i++) {
            scanf("%lld",&m);
            ok = false;
            while(m--){
                scanf("%lld",&x);
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) printf("OPTIMAL");
        else {
            printf("IMPROVE\n");
            for(long long i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;
const long long N = 1e5+5;
long long a[N];
long long t,m,n,ans;
main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> t;
    while(t--) {
        bool ok; ans = 0;
        cin >> n;
        memset(a,0,sizeof(a));
        for(long long i=1 ; i<=n ; i++) {
            cin >> m;
            ok = false;
            while(m--){
                long long x; cin >> x;
                if(!a[x] && !ok) a[x]++ , ok = true;
            }
            if (!ok) ans = i;
        }
        if(!ans) cout << "OPTIMAL";
        else {
            cout << "IMPROVE\n";
            for(long long i=1 ; i<=n ; i++)
                if (!a[i]) {
                    cout << ans << " " << i;
                    break;
                }
        }
        cout << '\n';
    }
}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz;
       cin>>siz;
       si[i]=siz;
       for(ll j=0;j<siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

           mat[i][j]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
       }
       else
       {
           mark=false;
       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll st,index;
       bool check=false;
       for(ll k=1;k<=n;++k)
       {
           if(dau[k]==false)
           {
               for(ll i=1;i<=n;++i)
               {
                   if(kin[i]==false && mat[k][i]==false)
                   {
                       check=true;
                       st=i;
                       index=k;
                       break;
                   }
               }
           }
           if(check==true)
           break;
       }
       cout<<"IMPROVE \n"<<st<<" "<<index;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
//   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz,val;
       cin>>siz;
       si[i]=siz;
       for(ll j=1;j<=siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

        //   mat[i][in]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
        //   ++m1[mini];
       }
       else
       {
           mark=false;
           val=i;

       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll k;
       for(ll i=1;i<=n;++i)
       {
           if(kin[i]==false )
           {
               k=i;
               break;
           }
       }
       cout<<"IMPROVE \n"<<val<<" "<<k;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz;
       cin>>siz;
       si[i]=siz;
       for(ll j=1;j<=siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

           mat[i][j]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
       }
       else
       {
           mark=false;
       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll st,index;
       bool check=false;
       for(ll k=1;k<=n;++k)
       {
           if(dau[k]==false)
           {
               for(ll i=1;i<=n;++i)
               {
                   if(kin[i]==false && mat[k][i]==false)
                   {
                       check=true;
                       st=i;
                       index=k;
                       break;
                   }
               }
           }
           if(check==true)
           break;
       }
       cout<<"IMPROVE \n"<<st<<" "<<index;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz,val;
       cin>>siz;
       si[i]=siz;
       for(ll j=1;j<=siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

           mat[i][in]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
       }
       else
       {
           mark=false;
           val=i;

       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll k;
       for(ll i=1;i<=n;++i)
       {
           if(kin[i]==false && mat[val][i]!=true)
           {
               k=i;
               break;
           }
       }
       cout<<"IMPROVE \n"<<val<<" "<<k;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz;
       cin>>siz;
       si[i]=siz;
       for(ll j=0;j<siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

           mat[i][j]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
       }
       else
       {
           mark=false;
           val=i;

       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll k;
       for(ll i=1;i<=n;++i)
       {
           if(kin[i]==false && mat[val][i]!=true)
           {
               k=i;
               break;
           }
       }
       cout<<"IMPROVE \n"<<val<<" "<<k;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz;
       cin>>siz;
       si[i]=siz;
       for(ll j=1;j<=siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

           mat[i][j]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
       }
       else
       {
           mark=false;
       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll st,index;
       bool check=false;
       for(ll k=1;k<=n;++k)
       {
           if(dau[k]==false)
           {
               for(ll i=1;i<=n;++i)
               {
                   if(kin[i]==false && mat[k][i]==false)
                   {
                       check=true;
                       st=i;
                       index=k;
                       break;
                   }
               }
           }
           if(check==true)
           break;
       }
       cout<<"IMPROVE \n"<<index<<" "<<st;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<unordered_map>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<limits.h>

using namespace std;

#define l long
#define ll long long
#define d double
#define ld long double
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b) for(i=a;i<b;++i)
#define rope(i,a,b) for(i=a;i<=b;++i)
#define MOD 1000000007

ll fast_power(ll base,ll power) {
    ll result = 1;
    while(power > 0) {

        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base) % MOD;
        }
        base = (base * base) % MOD;
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}

void work()
{
   ll n,in,val;
   cin>>n;
   vector<ll> v1[n+1];
   vector<ll> si(n+1);
   vector<vector<bool> >mat(n+1,vector<bool>(n+1,false));
   for(ll i=1;i<=n;++i)
   {
       ll siz;
       cin>>siz;
       si[i]=siz;
       for(ll j=1;j<=siz;++j)
       {
        //   cout<<"l";
           cin>>in;
           v1[i].push_back(in);

           mat[i][j]=true;
       }
   }

   vector<bool> kin(n+1,false),dau(n+1);
   bool mark=true;
   for(ll i=1;i<=n;++i)
   {
       ll mini=INT_MAX;
       for(ll j=0;j<v1[i].size();++j)
       {
           if(kin[v1[i][j]]==false && v1[i][j]<mini)
           {
               mini=v1[i][j];
           }
       }

       if(mini!=INT_MAX)
       {
           dau[i]=true;
           kin[mini]=true;
       }
       else
       {
           mark=false;
           val=i;

       }
   }

   if(mark==true)
   {
       cout<<"OPTIMAL";
   }
   else
   {
       ll k;
       for(ll i=1;i<=n;++i)
       {
           if(kin[i]==false && mat[val][i]!=true)
           {
               k=i;
               break;
           }
       }
       cout<<"IMPROVE \n"<<val<<" "<<k;
   }

}

int main()
{
    fast();

    ll test;
    cin>>test;
    ll i;
    loop(i,0,test)
    {
        work();
        cout<<"\n";
    }

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int k[n+5];
		int b[n+5]={0};
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			cin>>k[i];
			int fla=0;
			for(int j=1;j<=k[i];j++)
			{
				int x;
				cin>>x;
				if(b[x]==0&&fla==0)
				{
					b[x]++;
					fla=1;
				}
			}
			if(fla==0)
			ans=i;
		}
		if(!ans)
		{
			cout<<"OPTIMAL \n";
			continue;
		}
		cout<<"IMPROVE \n";
		for(int i=1;i<=n;i++)
		{
			if(b[i]==0)
			{
				cout<<ans<<" "<<i<<endl;
				break;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowBit(x) ((x)&(-x))
#define rep(i,a,n) for (ll i=a;i<=n;i++)
#define per(i,a,n) for (ll i=n;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
const ll mod=1e9+7;
const ll N=1e5+10;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll ans=1;while(b>0)
{if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;}
ll readn(){ll sum=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+(ch-'0');
ch=getchar();}return sum*f;}

ll _,n,m,op,re,aa;
bool b[100005];
VI v;
int main()
{
	_=readn();
	while(_--)
	{
		memset(b,false,sizeof(b));
		n=readn();
		rep(i,1,n){
			op=N;
			m=readn();
			rep(j,1,m){
				aa=readn();
				if(!b[aa])
				op=min(aa,op);
			}
			if(op!=N){
					b[op]=true;
				}else v.pb(i);
		}
		if(SZ(v)==0)puts("OPTIMAL");
		else {
			puts("IMPROVE");
			printf("%lld ",v[0]);
			rep(i,1,n)if(!b[i]){printf("%lld\n",i);break;}
		}
		v.clear();
	}
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<cmath>
#define MAXN 100010
#define ll long long
using namespace std;
bool a[MAXN],b[MAXN];
int numm[MAXN];
int n;

void work(){
	//freopen("1.in","r",stdin);
	cin>>n;int hh=0;

	for(int i=1;i<=n;i++){
		int k;scanf("%d",&k);
		for(int j=1;j<=k;j++) scanf("%d",&numm[j]);
		sort(numm+1,numm+k+1);
		for(int j=1;j<=k;j++){
			if(!b[numm[j]]){
				b[numm[j]]=1;a[i]=1;hh++;
				//cout<<i<<" "<<numm[j]<<endl;
				break;
			}
		}
	}
	if(hh==n){
		puts("OPTIMAL");
	}
	else{
        int x,y;
        for(int i=1;i<=n;i++) if(!a[i]) {
            x=i;break;
        }
        for(int i=1;i<=n;i++) if(!b[i]){
            y=i;break;
        }
        puts("IMPROVE");
        printf("%d %d\n",x,y);
	}
	for(int i=1;i<=n;i++) a[i]=b[i]=0;
}

int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int t;cin>>t;
	while(t--) work();
}


#include<bits/stdc++.h>
using namespace std;
bool md[20000];
vector<int> v[20000];
int t,n;
int main(){
	cin>>t;
	for(int I=0;I<t;I++){
		cin>>n;
		for(int i=0;i<n;i++){
			v[i].clear();
			md[i]=0;
		}
		for(int i=0;i<n;i++){
			int k;
			cin>>k;
			for(int j=0;j<k;j++){
				int a;
				cin>>a;
				a--;
				v[i].push_back(a);
			}
		}
		bool f=0;
		int G;
		for(int i=0;i<n;i++){
			bool F=0;
			for(int j=0;j<v[i].size();j++){
				if (md[v[i][j]]==0){
					md[v[i][j]]=1;
					F=1;
					break;
				}
			}
			if (F==0&&f==0){
				f=1;
				G=i;
			}
		}
		if (f==0){
			cout<<"OPTIMAL"<<endl;
		}else{
			cout<<"IMPROVE"<<endl;
			for(int i=0;i<n;i++){
				if(md[i]==0){
					cout<<G+1<<" "<<i+1<<endl;
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool a[100003],b[100003];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,t,k;
		scanf("%d",&n);
		for(int i=1; i<=n; i++)
		{
			bool f=1;
			scanf("%d",&k);

			for(int j=1; j<=k; j++)
			{
				scanf("%d",&t);
				if((!a[t]) &&f) {
					b[i]=a[t]=1;
					f=0;
			    }
		}
	}
	int x=0,y=0;
	for(int i=1; i<=n; i++) if(!a[i])
	{
		x=i; break;
	}
	for(int i=1; i<=n; i++) if(!b[i])
	{
		y=i; break;
	}
	if(x && y)
	printf("IMPROVE\n%d %d\n",y,x);
	else printf("OPTIMAL\n");
	for(int i=1; i<=n; i++) a[i]=b[i]=0;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n,q;
int a[1000005];
int vis[100005];
int cnt;
int ma;
int f;
int z;
int main(){
	scanf("%d",&t);
	for(int i=1;i<=t;i++){
		scanf("%d",&n);
		ma=0;
		f=0;
		z=0;
		for(int j=1;j<=n;j++){
			vis[j]=1;
		}
		for(int j=1;j<=n;j++){
			scanf("%d",&q);
			cnt=0;
			int flag=0;
			int h=0;
			for(int k=1;k<=q;k++){
				scanf("%d",&a[k]);
				if(vis[a[k]]==1&&h==0){
					vis[a[k]]=0;
					flag=1;
					h=1;
				}
			}
			if(flag==0&&f==0) f=j;
		}
		for(int j=1;j<=n;j++){
			if(vis[j]==1){
				printf("IMPROVE");
				printf("\n%d %d\n",f,j);
				z=1;
				break;
			}
		}
		if(z==0)printf("OPTIMAL\n");
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;

int main() {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		int a[maxn] = {0};
		int cnt[maxn] = {0};
		int ans = 0;

		for(int i = 1; i <= n; i++) {
			cin >> cnt[i];

			int flag = 0;
			for(int j = 1; j <= cnt[i]; j++) {
				int v;
				cin >> v;
				if(a[v] == 0 && flag == 0) {
					a[v] = 1;
					flag = 1;
				}
			}
			if(flag == 0) {
				ans = i;
			}
		}

		if(ans == 0) {
			cout << "OPTIMAL" << endl;
		} else {
			cout << "IMPROVE" << endl;
			for(int j = 1; j <= n; j++) {
				if(a[j] == 0) {
					cout << ans << ' ' << j << endl;
					break;
				}
			}
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define REP(i,first,last) for(int i=first;i<=last;++i)
#define DOW(i,first,last) for(int i=first;i>=last;--i)
using namespace std;
const int MAXN=114514*10;
int n,m;
int T;
void YES()
{
	printf("YES\n");
}
void NO()
{
	printf("NO\n");
}
void read(int &a)
{
	scanf("%d",&a);
}
int boo[MAXN],check[MAXN];
void work()
{
	scanf("%d",&n);
	REP(i,1,n)
	{
		boo[i]=check[i]=0;
	}
	int p,k;
	REP(i,1,n)
	{
		scanf("%d",&k);
		REP(j,1,k)
		{
			scanf("%d",&p);
			if(!boo[i]&&!check[p])
			{
				boo[i]=check[p]=1;
			}
		}
	}
	int l=n+1;
	REP(i,1,n)
	{
		if(!boo[i])
		{
			l=i;
			break;
		}
	}
	if(l>n)
	{
		printf("OPTIMAL\n");
		return;
	}
	printf("IMPROVE\n%d ",l);
	REP(i,1,n)
	{
		if(!check[i])
		{
			l=i;
			break;
		}
	}
	printf("%d\n",l);
}
int main()
{
	scanf("%d",&T);
	REP(i,1,T)
	{
		work();
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int T,n,k,x,y,maxdis,maxpos,mindis,minpos,cnt,ans1,ans2,sum1,sum2,a[100001];
bool f=0,vis[100001],vis2[100001];
int main()
{
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			vis[i]=vis2[i]=0;
		//vis[i]代表第i个王子有没有公主，vis2[i]代表第i个公主有没有王子
		sum1=sum2=ans1=ans2=0;
		//sum1代表的是匹配成功的情侣对数
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&k);
			for(int j=1;j<=k;j++) scanf("%d",&a[j]);
			maxdis=maxpos=0;
			cnt=1;
			//cnt代表当前的数出现了几次
			//maxdis代表出现最多的且没有公主的王子编号的出现次数
			//maxpos代表编号
			for(int j=1;j<=k;j++)
			{
				if(a[j]==a[j-1]) cnt++;//如果和上一个相同，则出现次数+1
				else cnt=1;
				if(cnt>maxdis&&!vis[a[j]]){
					//如果这个王子没有公主，并且出现次数比前面的王子出现次数多，就更改
					maxdis=cnt;
					maxpos=a[j];
				}
			}
			if(!vis[maxpos]&&maxpos) vis[maxpos]=vis2[i]=1,sum1++;
			//如果当前公主匹配成功，就标记下来匹配成功的一对。
		}
		if(sum1!=n)//如果有公主没有嫁出去
		{
			for(int i=1;i<=n;i++)
				if(!vis2[i]){
					ans1=i;
					break;
				}//找一个没有嫁出去的公主
			for(int i=1;i<=n;i++)
				if(!vis[i]){
					ans2=i;
					break;
				}//找一个没有公主的王子
		}
		if(ans1&&ans2) printf("IMPROVE\n%d %d\n",ans1,ans2);//如果找到了可以更改的一对，就输出
		else puts("OPTIMAL");//没有找到
	}
}


#include<iostream>
#include<cstring>
using namespace std;
#define INF 1e10+5
#define maxn 100005
#define minn -105
#define ld long double;
#define uint unsigned int;
#define ull unsigned long long;
typedef long long ll;
bool ok[maxn],gok[maxn];
void solve()
{
    memset(ok,0,sizeof(ok));
    int n, u;
    int index=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        gok[i]=0;
        int k;
        cin>>k;
        for(int j=0;j<k;j++)
        {
            cin>>u;
            if(!gok[i])if(!ok[u])ok[u]=gok[i]=1;
        }
        if(!gok[i])index=i;
    }
    if(!index){cout<<"OPTIMAL"<<endl;return;}
    int index2=-1;
    for(int i=1;i<=n;i++)
    if(!ok[i]){index2=i;break;}
    cout<<"IMPROVE"<<endl;
    cout<<index<<" "<<index2<<endl;

}
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
int t;
int main() {
	ios::sync_with_stdio(false);
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		int a[n + 5] = {0};
		int cnt[n + 5] = {0};
		int ans = 0;

		for(int i = 1; i <= n; i++) {
			cin >> cnt[i];

			int flag = 0;
			for(int j = 1; j <= cnt[i]; j++) {
				int v;
				cin >> v;
				if(a[v] == 0 && flag == 0) {
					a[v] = 1;
					flag = 1;
				}
			}
			if(flag == 0) {
				ans = i;
			}
		}

		if(ans == 0) {
			cout << "OPTIMAL" << endl;
		} else {
			cout << "IMPROVE" << endl;
			for(int j = 1; j <= n; j++) {
				if(a[j] == 0) {
					cout << ans << ' ' << j << endl;
					break;
				}
			}
		}
	}

	return 0;
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];
char th[100000000];

int main() {
    kt{

        int n;
        cin(n);
        for(int i=1;i<=n;i++){
            wz[i]=0;
            gz[i]=0;
        }
        for(int i=1;i<=n;i++){
            int k;
            cin(k);
            int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                cin(d);

                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    gets(th);
                    break;
                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];
char th[10000000];

int main() {
    kt{
        mem0(gz);
        mem0(wz);
        int n;
        cin(n);
        for(int i=1;i<=n;i++){
            int k;
            cin(k);
            int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                cin(d);

                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    gets(th);
                    break;
                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];
char th[10000000];
inline int read()
{
    char ch = getchar();
    ll x = 0, f = 1;
    while(ch > '9' || ch < '0')
    {
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

int main() {
    kt{
        mem0(gz);
        mem0(wz);
        int n;
        n=read();
        for(int i=1;i<=n;i++){
            int k;
            k=read();
       //     int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                d=read();

                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    gets(th);
                    break;
                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];
char th[10000000];
inline int read()
{
    char ch = getchar();
    int x = 0, f = 1;
    while(ch > '9' || ch < '0')
    {
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

int main() {
    kt{
        mem0(gz);
        mem0(wz);
        int n;
        n=read();
        for(int i=1;i<=n;i++){
            int k;
            k=read();
       //     int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                d=read();

                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    gets(th);
                    break;
                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];

int main() {
    kt{
        mem0(gz);
        mem0(wz);
        int n;
        cin(n);
        for(int i=1;i<=n;i++){
            int k;
            cin(k);
            int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                cin(d);
                if(flag==1){continue;}
                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    flag=1;

                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];
char th[100000000];

int main() {
    kt{
        mem0(gz);
        mem0(wz);
        int n;
        cin(n);
        for(int i=1;i<=n;i++){
            int k;
            cin(k);
            int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                cin(d);

                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    gets(th);
                    break;
                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;//别hack我了，都没分了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>

#define INT 0x7fffffff
#define  cin(x) scanf("%d",&x)
#define cinc(x) scanf("%c",&x);while(ch==' '||ch=='\n')scanf("%c",&x);
#define kt int T;scanf("%d",&T);while(T--)
#define mem0(x) memset(x,0,sizeof(x));
#define mem_1(x) memset(x,-1,sizeof(x));
#define INT2 0x7ffffff
#define  ll long long
using namespace std;
int gz[100010];
int wz[100010];
char th[10000000];

 inline ll read()
{
    char ch = getchar();
    ll x = 0, f = 1;
    while(ch > '9' || ch < '0')
    {
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

int main() {
    kt{
        mem0(gz);
        mem0(wz);
        ll n;
        n=read();
        for(int i=1;i<=n;i++){
            ll k;
            k=read();
            int flag=0;
            for(int j=1;j<=k;j++){
                int d;
                d=read();

                if(wz[d]==0){
                    gz[i]=d;
                    wz[d]=1;
                    gets(th);
                    break;
                }
            }

        }
        int jl=-1;
        int jl2=-1;
        for(int i=1;i<=n;i++){
            if(gz[i]==0){
                jl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(wz[i]==0){
                jl2=i;
                break;
            }
        }
        if(jl==-1){
            cout<<"OPTIMAL"<<endl;
        }
        else cout<<"IMPROVE"<<endl<<jl<<' '<<jl2<<endl;
    };
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef long long ll;

int main() {
	//freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int t;
  cin >> t;
  while (t--) {
  	int n;
  	cin >> n;
  	bool A[n+1];
  	for (int i = 1; i <= n; i++) {
  		A[i] = false;
  	}
  	int tt = n;
  	bool B[n+1];
  	for (int i = 1; i <= n; i++)  B[i] = false;
  	bool flag = false;
  	int kindom, princess;
  	for (tt = 1; tt <= n; tt++) {
  		int sz;
  		cin >> sz;
  		int ara[sz];
  		for (auto &it : ara)
  			cin >> it;
  		sort(ara, ara + sz);
  		for (int i = 0; i < sz; i++) {
	  		if (!A[ara[i]]) {
	  			A[ara[i]] = true;
	  			B[tt] = true;
	  			break;
	  		}
	  	}
  	}
  	for (int i = 1; i <= n; i++) {
  			if (A[i] == false) {
  				flag = true;
  				kindom = i;
  				break;
  			}
  		}
  		for (int i = 1; i <= n; i++) {
  			if (B[i] == false) {
  				princess = i;
  				break;
  			}
  		}
  		if (flag) {
  			cout << "IMPROVE" << endl;
  			cout << princess << ' ' << kindom << endl;
  		}
  		else cout << "OPTIMAL" << endl;

  	}
  }


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef long long ll;

int main() {
	freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  int t;
  cin >> t;
  while (t--) {
  	int n;
  	cin >> n;
  	bool A[n+1];
  	for (int i = 1; i <= n; i++) {
  		A[i] = false;
  	}
  	int tt = n;
  	bool B[n+1];
  	for (int i = 1; i <= n; i++)  B[i] = false;
  	bool flag = false;
  	int kindom, princess;
  	for (tt = 1; tt <= n; tt++) {
  		int sz;
  		cin >> sz;
  		int ara[sz];
  		for (auto &it : ara)
  			cin >> it;
  		sort(ara, ara + sz);
  		for (int i = 0; i < sz; i++) {
	  		if (!A[ara[i]]) {
	  			A[ara[i]] = true;
	  			B[tt] = true;
	  			break;
	  		}
	  	}
  	}
  	for (int i = 1; i <= n; i++) {
  			if (A[i] == false) {
  				flag = true;
  				kindom = i;
  				break;
  			}
  		}
  		for (int i = 1; i <= n; i++) {
  			if (B[i] == false) {
  				princess = i;
  				break;
  			}
  		}
  		// for (int i = 1; i <= n; i++) {
  		// 	cout << A[i] << endl;
  		// }
  		// cout << endl;
  		// for (int i = 1; i <= n; i++) {
  		// 	cout << B[i] << endl;
  		// }
  		if (flag) {
  			cout << "IMPROVE" << endl;
  			cout << princess << ' ' << kindom << endl;
  		}
  		else cout << "OPTIMAL" << endl;

  	}
  }


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef long long ll;

int main() {
	//freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int t;
  cin >> t;
  while (t--) {
  	int n;
  	cin >> n;
  	bool A[n+1];
  	for (int i = 1; i <= n; i++) {
  		A[i] = false;
  	}
  	int tt = n;
  	bool B[n+1];
  	for (int i = 1; i <= n; i++)  B[i] = false;
  	bool flag = false;
  	int kindom, princess;
  	for (tt = 1; tt <= n; tt++) {
  		int sz;
  		cin >> sz;
  		int ara[sz];
  		for (auto &it : ara)
  			cin >> it;
  		sort(ara, ara + sz);
  		for (int i = 0; i < sz; i++) {
	  		if (!A[ara[i]]) {
	  			A[ara[i]] = true;
	  			B[i] = true;
	  			break;
	  		}
	  	}
  	}
  	for (int i = 1; i <= n; i++) {
  			if (A[i] == false) {
  				flag = true;
  				kindom = i;
  				break;
  			}
  		}
  		for (int i = 1; i <= n; i++) {
  			if (B[i] == false) {
  				princess = i;
  				break;
  			}
  		}
  		if (flag) {
  			cout << "IMPROVE" << endl;
  			cout << princess << ' ' << kindom << endl;
  		}
  		else cout << "OPTIMAL" << endl;

  	}
  }


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef long long ll;

int main() {
	//freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int t;
  cin >> t;
  while (t--) {
  	int n;
  	cin >> n;
  	bool A[n+1];
  	for (int i = 1; i <= n; i++) {
  		A[i] = false;
  	}
  	int tt = n;
  	bool B[n+1];
  	for (int i = 1; i <= n; i++)  B[i] = false;
  	bool flag = false;
  	int kindom, princess;
  	for (tt = 1; tt <= n; tt++) {
  		int sz;
  		cin >> sz;
  		int ara[sz];
  		for (auto &it : ara)
  			cin >> it;
  		sort(ara, ara + sz);
  		for (int i = 0; i < sz; i++) {
	  		if (!A[ara[i]]) {
	  			A[ara[i]] = true;
	  			B[tt] = true;
	  			break;
	  		}
	  	}
  	}
  	for (int i = 1; i <= n; i++) {
  			if (A[i] == false) {
  				flag = true;
  				kindom = i;
  				break;
  			}
  		}
  		for (int i = 1; i <= n; i++) {
  			if (B[i] == false) {
  				princess = i;
  				break;
  			}
  		}
  		// for (int i = 1; i <= n; i++) {
  		// 	cout << A[i] << endl;
  		// }
  		// cout << endl;
  		// for (int i = 1; i <= n; i++) {
  		// 	cout << B[i] << endl;
  		// }
  		if (flag) {
  			cout << "IMPROVE" << endl;
  			cout << princess << ' ' << kindom << endl;
  		}
  		else cout << "OPTIMAL" << endl;

  	}
  }


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

#define LL long long
#define Debug(x) cerr << #x << ": " << x << endl;

inline int read() {
	char c = getchar(); int x = 0, f = 1;
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 1e6 + 5;

int a[MAXN]; int N; bool vis[MAXN];

inline void solve() {
	N = read();
	for (int i = 1; i <= N; i++) vis[i] = false;
	bool allflg = true; int pos = 0;
	for (int i = 1; i <= N; i++) {
		int ct = read();
		for (int j = 1; j <= ct; j++) a[j] = read();
		//sort(a + 1, a + ct + 1);
		bool flg = false;
		for (int j = 1; j <= ct; j++)
			if (!vis[a[j]]) {
				vis[a[j]] = true; flg = true; break;
			}
		if (!flg) {
			allflg = false; pos = i; //break;
		}
	}
	if (!allflg) {
		bool flg = false;
		for (int i = 1; i <= N; i++)
			if (!vis[i]) {
				puts("IMPROVE");
				printf("%d %d\n", pos, i);
				flg = true;
				break;
			}
		if (!flg) puts("OPTIMAL");
	} else {
		puts("OPTIMAL");
	}
}

int main() {
	int T = read();
	while (T--) solve();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
int t;
int main() {
	ios::sync_with_stdio(false);
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		int a[n + 5] = {0};
		int cnt;
		int ans = 0;

		for(int i = 1; i <= n; i++) {
			cin >> cnt;

			int flag = 0;
			for(int j = 1; j <= cnt; j++) {
				int v;
				cin >> v;
				if(a[v] == 0 && flag == 0) {
					a[v] = 1;
					flag = 1;
				}
			}
			if(flag == 0) {
				ans = i;
			}
		}

		if(ans == 0) {
			cout << "OPTIMAL" << endl;
		} else {
			cout << "IMPROVE" << endl;
			for(int j = 1; j <= n; j++) {
				if(a[j] == 0) {
					cout << ans << ' ' << j << endl;
					break;
				}
			}
		}
	}

	return 0;
}


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

int t,n;
bool book[100001],fin[100001];

int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++)book[i]=fin[i]=0;
        for(int i=1;i<=n;i++){
            int k;cin>>k;
            for(int j=1;j<=k;j++){
                int x;cin>>x;
                if(!fin[i]){
                    if(!book[x])
                        book[x]=fin[i]=1;
                }
            }//qwq
        }
        int girl,boy;
        girl=boy=0;
        for(int i=1;i<=n;i++){
            if(!fin[i]){
                girl=i;
                break;
            }
        }
        for(int i=1;i<=n;i++){
            if(!book[i]){
                boy=i;
                break;
            }
        }
        if(girl==0)cout<<"OPTIMAL"<<endl;
        else cout<<"IMPROVE"<<'\n'<<girl<<' '<<boy<<endl;
    }
}