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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using ull = unsigned long long;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
 
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
 
#define tcT template<class T
#define tcTU tcT, class U
 
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define rrep(i,a,b) for(int i = (b) - 1; i >= (a); i--)
 
const db PI = acos(-1);
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
 
tcT> bool ckmin(T& a, const T& b) { return b < a ? a=b, 1 : 0; }
tcT> bool ckmax(T& a, const T& b) { return a < b ? a=b, 1 : 0; }
 
tcT> void _dbg(const char *sdbg, T h){ cerr<<sdbg<<'='<<h<<endl; }
tcT, class... TA> void _dbg(const char *sdbg, T h, TA... a) {
	while(*sdbg!=',') cerr<<*sdbg++;
	cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
 
tcT> ostream &operator<<(ostream& os, vector<T> V) {
	os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
tcT, class V> ostream &operator<<(ostream &os, pair<T,V> P) {
	return os << "(" << P.f << "," << P.s << ")";
}
 
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

struct kVC {
	int n;
	vector<vi> g;
	vi deg;
	int k;
	vector<bool> in_cover;
	vector<vector<bool>> in_cover_final;
	int cover_size;
	bool any_cover;

	kVC(int _n, int _k) : n(_n), g(_n), deg(_n, 0), k(_k), in_cover(_n, false), in_cover_final(_k+1), cover_size(0), any_cover(false) {
		rep(i,0,k+1) {
			in_cover_final[i].resize(n, false);
		}
	}

	void add_to_cover(int u) {
		in_cover[u] = true;;
		cover_size++;

		for (int v : g[u]) {
			if (in_cover[v]) continue;
			deg[v]--;
			deg[u]--;
		}
	}

	void delete_from_cover(int u) {
		in_cover[u] = false;
		cover_size--;

		for (int v : g[u]) {
			if (in_cover[v]) continue;
			deg[v]++;
			deg[u]++;
		}
	}

	void solve_primitive() {
		int vis[n];
		bool vis2[n];
		fill(vis, vis+n, 0);
		fill(vis2, vis2+n, false);

		int dsusize = 0;

		function<void(int, int)> mark_all = [&](int u, int col) {
			vis[u] = col + 1;
			dsusize++;

			for (int v : g[u]) {
				if (vis[v] || in_cover[v]) continue;
				mark_all(v, col^1);
			}
		};

		function<void(int)> remark = [&](int u) {
			vis2[u] = true;
			vis[u] = 2;

			for (int v : g[u]) {
				if (vis2[v] || in_cover[v]) continue;
				remark(v);
			}
		};

		int res = 0;

		// sciezki
		rep(i,0,n) {
			if (vis[i] || deg[i] != 1) continue;

			dsusize = 0;
			mark_all(i, 0);

			res += dsusize / 2;

			if (cover_size + res > k) return;

			if (dsusize % 2 == 0) {
				remark(i);
			}
		}

		// cykle
		rep(i,0,n) {
			if (vis[i] || deg[i] == 0) continue;

			dsusize = 0;
			mark_all(i,1);

			res += (dsusize + 1) / 2;

			if (cover_size + res > k) return;

			remark(i);
		}

		rep(i,0,n) {
			if (vis[i] == 2 || in_cover[i]) {
				in_cover_final[cover_size + res][i] = true;
			}
		}

		any_cover = true;
		ckmin(k, cover_size + res);
	}

	void getvc() {
		if (cover_size > k) return;
		int max_deg_vertex = 0;

		rep(i,1,n) {
			if (deg[i] > deg[max_deg_vertex]) {
				max_deg_vertex = i;
			}
		}

		if (k == 0 && deg[max_deg_vertex] > 0) {
			return;
		}

		// only paths and cycles
		if (deg[max_deg_vertex] < 3) {
			solve_primitive();
			return;
		}

		add_to_cover(max_deg_vertex);
		getvc();
		delete_from_cover(max_deg_vertex);


		vi added_to_cover;
		for (int v : g[max_deg_vertex]) {
			if (!in_cover[v]) {
				add_to_cover(v);
				added_to_cover.pb(v);
				if (cover_size > k) break;
			}
		}

		if (cover_size <= k) {
			getvc();
		}

		for (int v : added_to_cover) {
			delete_from_cover(v);
		}
	}
};

void solve() {
	int n, m, k;
	cin >> n >> m >> k;

	vi input_g[n];
	set<pair<int, int>> edges;

	rep(i,0,m) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		if (a > b) swap(a, b);

		if (edges.count(mp(a, b))) continue;
		edges.insert(mp(a, b));

		input_g[a].pb(b);
		input_g[b].pb(a);
	}

	set<int> must_be_in_cover;
	set<int> interesting;

	rep(u,0,n) {
		if (sz(input_g[u]) > k) {
			must_be_in_cover.insert(u);
			continue;
		}

		for (int v : input_g[u]) {
			if (sz(input_g[v]) <= k) {
				interesting.insert(u);
				break;
			}
		}
	}

	if (sz(must_be_in_cover) > k) {
		cout << "-1\n";
		return;
	}

	int sc[n], scr[n];
	int sct = 0;

	for (int i : interesting) {
		sc[i] = sct++;
		scr[sc[i]] = i;
	}

	if (sz(interesting) == 0) {
		cout << sz(must_be_in_cover) << " " << sz(must_be_in_cover) << "\n";
		for (int v : must_be_in_cover) {
			cout << v+1 << " ";
		}
		cout << "\n";
		return;
	}

	kVC kvc(sz(interesting), k - sz(must_be_in_cover));

	for (int u : interesting) {
		for (int v : input_g[u]) {
			if (must_be_in_cover.count(v)) continue;
			kvc.g[sc[u]].pb(sc[v]);
			kvc.deg[sc[u]]++;
		}
	}

	kvc.getvc();

	if (!kvc.any_cover) {
		cout << "-1\n";
		return;
	}

	vi res;
	rep(i,0,kvc.n) {
		if (kvc.in_cover_final[kvc.k][i]) {
			res.pb(scr[i]);
		}
	}

	for (int i : must_be_in_cover) {
		res.pb(i);
	}

	sort(all(res));

	cout << kvc.k + sz(must_be_in_cover) << " " << sz(res) << "\n";
	for (int v : res) cout << v+1 << " ";
	cout << "\n";
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int t;
	cin >> t;
	while (t--) solve(); 

	return 0;
}