1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<queue>
5 #include<vector>
6 using namespace std;
7 const int maxn=2e5+7;
8 int a[maxn],b[maxn],c[maxn];
9 struct Node{int l,r;}p[maxn];
10 vector<int>ans;
11 int main()
12 {
13 int T;
14 scanf("%d",&T);
15 while(T--)
16 {
17 ans.clear();
18 memset(a,0,sizeof(a));
19 memset(c,0,sizeof(c));
20 int n,m;
21 scanf("%d%d",&n,&m);
22 for(int i=0;i<m;i++)
23 {
24 int x,y;
25 scanf("%d%d",&x,&y);
26 a[x]++,a[n+y]--;
27 p[i].l=x,p[i].r=y;
28 }
29 int cnt=0;
30 for(int i=1;i<=n;i++)
31 {
32 cnt+=a[i];
33 b[i]=cnt;
34 cnt+=a[n+i];
35 }
36 for(int i=1;i<=n;i++)
37 {
38 if(b[i]>1)c[i]=c[i-1]+1;
39 else c[i]=c[i-1];
40 }
41 for(int i=0;i<m;i++)
42 {
43 if(c[p[i].r]-c[p[i].l-1]==p[i].r-p[i].l+1)
44 ans.push_back(i);
45 }
46 int len=ans.size();
47 printf("%d\n",len);
48 if(len)
49 {
50 for(int i=0;i<len-1;i++)
51 printf("%d ",ans[i]+1);
52 printf("%d\n",ans[len-1]+1);
53 }
54 }
55 return 0;
56 }