#include <stdio.h> #include <string.h> #define clr(a) memset(a,0,sizeof(a)) #define N 10005 #define M 100005 int MIN(int a,int b) { if(a<b) return a; else return b; } struct Node { int j,tag,id; Node *next; }; int n,m,nid,memp; Node mem[M*2],*e[N]; int bridge[M],nbridge,low[N],dfn[N],vis[N]; int addedge(Node *e[],int i,int j) { Node* p; for(p=e[i];p!=NULL;p=p->next) if(p->j==j) break; if(p!=NULL) { p->tag++; return 0; } p=&mem[memp++]; p->j=j;p->next=e[i];e[i]=p;p->id=nid;p->tag=0; return 1; } void dfs(int i,int father,int dth) { int j; vis[i]=1;dfn[i]=low[i]=dth; Node *p; for(p=e[i];p!=NULL;p=p->next) { j=p->j; if(j!=father&&vis[j]==1) low[i]=MIN(low[i],dfn[j]); if(vis[j]==0) { dfs(j,i,dth+1); low[i]=MIN(low[i],low[j]); if(low[j]>dfn[i]&&!p->tag) bridge[p->id]=++nbridge; } } } int main() { int i,j,k,t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memp=0;nid=0;clr(e); for(k=0;k<m;k++,nid++) { scanf("%d%d",&i,&j); addedge(e,i-1,j-1); addedge(e,j-1,i-1); bridge[nid]=0; } nbridge=0;clr(vis); dfs(0,-1,1); printf("%d ",nbridge); for(i=0,k=nbridge;i<m;i++) { if(bridge[i]) { printf("%d",i+1); if(--k) printf(" "); } } if(nbridge) puts(""); if(t) puts(""); } return 0; }