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
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = b; i >= a; i--)
#define cat(x) cout << #x << ": " << x << endl

using namespace std;
using ll = long long;

const int N = 3030;

mt19937 rnd(time(0));

struct Matching {	// [1, n]
	vector<int> e[N];
	int mate[N], vis[N];
	void clear() {
		rep(i, 1, N - 1) e[i].clear();
	}
	void add(int a, int b) {
		if (a == b) return;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	bool dfs(int a) {
		shuffle(e[a].begin(), e[a].end(), rnd);
		vis[a] = 1;
		for (auto b : e[a]) {
			int c = mate[b];
			if (vis[c]) continue;
			mate[a] = b; mate[b] = a; mate[c] = 0;
			if (!c || dfs(c)) return 1;
			mate[a] = 0; mate[b] = c; mate[c] = b;
		}
		return 0;
	}
	vector<pair<int, int>> matching(int n) {
		vector<pair<int, int>> res;
		rep(_, 1, 20) {
			rep(i, 1, n) mate[i] = 0;
			rep(i, 1, n) {
				if (!mate[i]) {
					rep(i, 1, n) vis[i] = 0;
					dfs(i);
				}
			}
			vector<pair<int, int>> cur;
			rep(i, 1, n) if (mate[i] > i) cur.push_back({i, mate[i]});
			if (cur.size() > res.size()) res = cur;
		}
		return res;
	}
} Match;

int lowerbound, upperbound;
int n, m, k, ord[N], vis[N], finish, cnt[N], exist[N], min_cover, marked;
vector<int> e[N];

inline void mark(int x) {
	if (cnt[x] == 0) marked++;
	cnt[x]++;
}

inline void unmark(int x) {
	cnt[x]--;
	if (cnt[x] == 0) marked--;
}

void vertex_cover(int x) {
	if (marked > upperbound) return;

	if (x == finish) {
		if (marked < min_cover) {
			upperbound = marked;
			min_cover = marked;
			rep(i, 1, n) exist[i] = 0;
		}
		if (marked == min_cover) {
			rep(i, 1, n) exist[i] |= cnt[i] > 0;
			// int c = 0;
			// rep(i, 1, n) c += (exist[i] |= cnt[i] > 0);
			// if (lowerbound == upperbound && c == n) {
			// 	upperbound = -1;
			// }
		}
		return;
	}

	int u = ord[x];

	// mark
	mark(u);
	vertex_cover(x + 1);
	unmark(u);

	// dont mark
	if (cnt[u] == 0) {
		for (auto v : e[u]) {
			mark(v);
		}

		vertex_cover(x + 1);

		for (auto v : e[u]) {
			unmark(v);
		}
	}
}

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

	Match.clear();
	marked = 0;
	upperbound = k;
	min_cover = n + 1;
	rep(i, 0, n + 1) {
		exist[i] = 0;
		cnt[i] = 0;
		vis[i] = 0;
		ord[i] = 0;
		e[i].clear();
	}

	rep(i, 1, m) {
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
		Match.add(a, b);
	}

	lowerbound = Match.matching(n).size();
	// in the best scenario min_cover(u) = matching - 1
	if (lowerbound > k) {
		cout << "-1\n";
		return;
	}

	rep(i, 1, n) {
		int u = 0;
		rep(j, 1, n) {
			if (!vis[j] && e[u].size() <= e[j].size()) {
				u = j;
			}
		}
		ord[i] = u;
		vis[u] = 1;

		for (auto v : e[u]) {
			auto it = find(e[v].begin(), e[v].end(), u);
			assert(it != e[v].end());
			e[v].erase(it);
		}
	}

	finish = 1;
	while (e[ord[finish]].size() > 0) {
		finish++;
	}

	vertex_cover(1);

	// min_cover(u) = min_cover - 1 for some u
	if (min_cover > k) {
		cout << "-1\n";
		return;
	}

	vector<int> leaving;
	rep(i, 1, n) {
		if (exist[i]) {
			leaving.push_back(i);
		}
	}

	cout << min_cover << " " << leaving.size() << "\n";
	for (auto x : leaving) {
		cout << x << " ";
	}
	cout << "\n";
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

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

	return 0;
}