1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(1); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1010;
int n,m,k,vis[N],T,pt[N],pc[N];
VI dn[N];
set<int> E[N];

struct node {
	node *l,*r;
	int val;
}pool[N*3],*cur=pool,*nd[N],*head[50],*tail[50];
void solve() {
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++) {
		E[i].clear();		
	}
	for (int i=0;i<m;i++) {
		int u,v;
		scanf("%d%d",&u,&v);
		E[u].insert(v);
		E[v].insert(u);
	}
	VI must,cand;
	while (1) {
		bool fd=0;
		rep(i,1,n+1) if (SZ(E[i])>k) {
			fd=1;
			must.pb(i);
			for (auto v:E[i]) E[v].erase(i);
			--k;
			E[i].clear();
		}
		if (!fd||k<0) break;
	}
	int te=0;
	rep(i,1,n+1) te+=SZ(E[i]);
	te/=2;
	if (te>k*k||k<0) {
		puts("-1");
		return;
	}
	int mv=k;
	int cc=0;
	//set<PII> deg;
	cur=pool;
	auto newnode=[&]() {
		node *p=cur++;
		p->val=0;
		p->l=p->r=NULL;
		return p;
	};
	rep(i,1,n+1) {
		nd[i]=newnode();
		nd[i]->val=i;
	}
	rep(i,0,30+1) {
		head[i]=newnode();
		tail[i]=newnode();
		head[i]->r=tail[i];
		tail[i]->l=head[i];
	}
	auto addl=[&](int d,node *v) {
		node *q=tail[d],*p=tail[d]->l;
		p->r=v; q->l=v;
		v->l=p; v->r=q;
	};
	auto dell=[&](node *v) {
		v->l->r=v->r;
		v->r->l=v->l;
	};

	rep(i,1,n+1) addl(SZ(E[i]),nd[i]);
	bool sol=0;
	function<void(int)> dfs=[&](int dep) {
		if (dep>mv) return;
		int lag=0,lagp=0;
		for (int j=k;j>=0;j--) {
			if (head[j]->r!=tail[j]) { 
				lag=j;
				lagp=head[j]->r->val;
				break;
			}
		}
		if (lag<=2) {
			++cc;
			VI vec,pos;
			for (int j=1;j<=2;j++) {
				for (auto it=head[j]->r;it!=tail[j];it=it->r) {
					vec.pb(it->val);
				}
			}
			++T;
			int ps=0,d=0;
			function<void(int)> dfs2=[&](int u) {
				pt[d++]=u;
				vis[u]=T;
				for (auto v:E[u]) if (vis[v]!=T) dfs2(v);
			};
			for (auto u:vec) if (SZ(E[u])==1&&vis[u]!=T) {
				d=0;
				dfs2(u);
				ps+=d/2;
				if (d%2==1) {
					for (int i=1;i<d;i+=2) pos.pb(pt[i]);
				} else {
					for (int i=0;i<d;i++) pos.pb(pt[i]);
				}
			}
			for (auto u:vec) if (vis[u]!=T) {
				d=0;
				dfs2(u);
				ps+=(d+1)/2;
				for (int i=0;i<d;i++) pos.pb(pt[i]);
			}
			//printf("%d %d\n",cc,dep+ps);
			if (dep+ps>mv) return;
			if (dep+ps<mv) {
				sol=1;
				mv=dep+ps; cand.clear();
			}
			if (dep+ps==mv) {
				sol=1;
				for (auto p:pos) cand.pb(p);
				rep(i,0,dep) cand.pb(pc[i]);
			}
		} else {
			int u=lagp;
			auto del=[&](int dep,int u) {
				dn[dep]=VI(all(E[u]));
				pc[dep]=u;
				for (auto v:E[u]) {
					dell(nd[v]);
					//deg.erase(mp(SZ(E[v]),v));
					E[v].erase(u);
					addl(SZ(E[v]),nd[v]);
					//deg.insert(mp(SZ(E[v]),v));
				}
				dell(nd[u]);
				//deg.erase(mp(SZ(E[u]),u));
				E[u].clear();
			};
			auto recov=[&](int dep,int u) {
				for (auto v:dn[dep]) {
					E[u].insert(v);
					dell(nd[v]);
					//deg.erase(mp(SZ(E[v]),v));
					E[v].insert(u);
					addl(SZ(E[v]),nd[v]);
					//deg.insert(mp(SZ(E[v]),v));
				}
				addl(SZ(E[u]),nd[u]);
				//deg.insert(mp(SZ(E[u]),u));
			};
			del(dep,u);
			dfs(dep+1);
			recov(dep,u);
			VI nei=VI(all(E[u]));
			if (dep+SZ(nei)<=mv) {
				rep(j,0,SZ(nei)) del(dep+j,nei[j]);
				dfs(dep+SZ(nei));
				per(j,0,SZ(nei)) recov(dep+j,nei[j]);				
			}
		}
	};
	dfs(0);
	if (!sol) {
		puts("-1");
		return;
	}
	for (auto p:must) cand.pb(p);
	sort(all(cand)); cand.erase(unique(all(cand)),cand.end());
	printf("%d %d\n",SZ(must)+mv,SZ(cand));
	for (auto p:cand) printf("%d ",p); puts("");
}

int _;
int main() {
	for (scanf("%d",&_);_;_--) {
		solve();
	}
}