#include <bits/stdc++.h>
using namespace std;
//#define int ll
using ll = long long;
using db = long double;
using pi = pair<int, int>;
using mi = map<int, int>;
#define fi first
#define ses second
#define vt vector
#define sz size()
#define eb emplace_back
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}//Ҫ��MODΪ����
ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return a;}ll ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
ll getInv(int a,int mod){ll x,y;ll d=exgcd(a,mod,x,y);return d==1?(x%mod+mod)%mod:-1;}//��a��mod�µ���Ԫ����������Ԫ����-1����Ҫ��MODΪ����

using vi = vt<int>;
const int N = 4e5 + 5;
int  M = 1e9 + 7;

inline int add(int x, int y) { return x + y >= M ? x + y - M : x + y; }
inline int mul(int x, int y) { return x * y % M; }
inline int sub(int x, int y) { return x - y < 0 ? x - y + M : x - y; }


using G = vt<vi>;

#define mid (l+r>>1)
#define lc p<<1
#define rc lc|1
#define lson lc,l,mid
#define rson rc,mid+1,r
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        vector<vector<int>>se(n + 1);
        int ans = 0;
        vector<int>k(n + 1, 0);
        vector<int>large;
        vector<int>small;
        vector<int>a;
        rep(i, 1, n)
        {
            cin >> k[i];
            ans += k[i];
            rep(j, 1, k[i])
            {
                int x;
                cin >> x;
                a.eb(x);
                se[i].eb(x);
            }
        }
        sort(all(a));
        a.erase(unique(all(a)), a.end());
        rep(i, 1, n)
        {
            for(int &x : se[i])
            {
                x = lower_bound(all(a), x) - a.begin();
            }
            sort(all(se[i]));
            //cout << endl;
        }
        vector<int>vis(a.sz + 1, 0);
        ans = sqrt(ans);
        rep(i, 1, n)
        {
            if(k[i] > ans)
            {
                large.eb(i);
            }
            else small.eb(i);
        }
        int L = -1, R = -1 ;
        for(int ind : large)
        {
            for(int &x : vis) x = 0;
            for(int &x : se[ind])
            {
                vis[x] = 1;
            }
            for(int i = 1; i <= n; ++i)
            {
                int cnt = 0;
                if(i == ind) continue;
                for(int y : se[i])
                {
                    if(vis[y]) cnt++;
                }
                if(cnt >= 2) L = ind, R = i;
            }
        }
        vector<vector<int>>pi(a.sz + 1);
        int l = -1, r = -1;
        for(int ind : small)
        {
            for(int i = 0; i < se[ind].sz; ++i)
            {
                for(int j = i + 1; j < se[ind].sz; ++j){
                    pi[se[ind][i]].eb(se[ind][j]);
                }
            }
        }
       // cout << "ss" << endl;
        rep(i, 0, a.size())
        {
            for(auto &x : pi[i])
            {
                vis[x] = 0;
            }
            for(auto &x : pi[i])
            {
                if(vis[x])
                {
                    l = i;
                    r = x;
                }
                vis[x] = 1;
            }
        }
        if(l != -1)
        {
            if(l > r) swap(l, r);
            int cnt = 0;
            for(int ind : small)
            {
                int res = 0;
                int now = l;
                for(int x : se[ind])
                {
                    if(x == now)
                    {
                        res++;
                        now = r;
                    }
                }
                if(res >= 2)
                {
                    if(!cnt)
                    cnt = ind;
                    else{
                        L = cnt, R = ind;
                    }
                }

            }

        }
        if(L == -1)
        {
            cout << L << endl;
        }
        else cout << L << ' ' << R << endl;

    }
}
