#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define EPS 1e-6
#define N 110000
#define met(a,b) (memset(a,b,sizeof(a)))
#define Lson r<<1
#define Rson r<<1|1
struct E
{
int L, R;
}a[N];
int v[N];
struct node
{
int L, R, x;
int mid()
{
return (L+R)/2;
}
int len()
{
return (R-L+1);
}
}Tree[N<<2];
void BuildTree(int r, int L, int R)
{
Tree[r].L = L, Tree[r].R = R, Tree[r].x = 0;
if(L==R)
return ;
BuildTree(Lson, L, Tree[r].mid());
BuildTree(Rson, Tree[r].mid()+1, R);
}
void Update(int r, int L, int R)
{
if(Tree[r].L==L && Tree[r].R==R)
{
Tree[r].x++;
return ;
}
if(R<=Tree[r].mid())
Update(Lson, L, R);
else if(L>Tree[r].mid())
Update(Rson, L, R);
else
{
Update(Lson, L, Tree[r].mid());
Update(Rson, Tree[r].mid()+1, R);
}
}
void Up(int r, int L, int R)
{
if(L==R)
return ;
Tree[Lson].x += Tree[r].x;
Tree[Rson].x += Tree[r].x;
Up(Lson, L, Tree[r].mid());
Up(Rson, Tree[r].mid()+1, R);
Tree[r].x = min(Tree[Lson].x, Tree[Rson].x);
}
int Query(int r, int L, int R)
{
if(Tree[r].L==L && Tree[r].R==R)
return Tree[r].x;
if(R<=Tree[r].mid())
return Query(Lson, L, R);
else if(L>Tree[r].mid())
return Query(Rson, L, R);
else
return min(Query(Lson, L, Tree[r].mid()), Query(Rson, Tree[r].mid()+1, R));
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, m, i, k=0, ans;
scanf("%d%d", &n, &m);
met(a,0);
met(v,0);
BuildTree(1, 1, n);
for(i=1; i<=m; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
Update(1, a[i].L, a[i].R);
}
Up(1, 1, n);
for(i=1; i<=m; i++)
{
ans = Query(1, a[i].L, a[i].R);
if(ans>=2)
v[k++] = i;
}
printf("%d\n", k);
for(i=0; i<k; i++)
printf("%d%c", v[i], i==k-1?‘\n‘:‘ ‘);
}
return 0;
}