#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using cr = const T &;
struct p
{
    int l, r, id;
} a[50050];
bool cmp(cr<p> l, cr<p> r)
{
    return l.l == r.l ? l.r < r.r : l.l < r.l;
}
bool cmp2(cr<p> l, cr<p> r)
{
    return l.r == r.r ? l.l < r.l : l.r > r.r;
}
int ans[50050];
int main()
{
    int T, n;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d%d", &a[i].l, &a[i].r), a[i].id = i + 1;
        sort(a, a + n, cmp);
        int cnt = 0;
        p ps[3] = {a[0], a[1]};
        for (int i = 2; i < n; i++)
        {
            ps[2] = a[i];
            sort(ps, ps + 3, cmp);
            bool f = ps[1].l <= ps[0].r && ps[2].l <= ps[0].r && ps[2].l <= ps[1].r;
            sort(ps, ps + 3, cmp2);
            if (f) ans[cnt++] = ps[0].id, swap(ps[0], ps[2]);
        }
        sort(ans, ans + cnt);
        printf("%d\n", cnt);
        for (int i = 0; i < cnt; i++) printf("%d ", ans[i]);
        putchar('\n');
    }
    return 0;
}