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
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define LSB(x) __builtin_ctzll(x)
#define ARG(x, i) (get<i>(x))
#define ithBit(m, i) ((m) >> (i) & 1)
#define pb push_back
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b);	}
template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = max(a, (T1)b);	}

template <typename Tp> void dedup(vector <Tp>& T)
{
	sort(ALL(T));
	T.resize(unique(ALL(T)) - T.begin());
}

const int maxN = 3003, maxK = 30;

vector <int> V, G[maxN];
bool vis[maxN], found[maxN];
int n;

void reset(bool* t)
{
	fill(t, t+n+1, false);
}

int effectiveDeg(int v)
{
	if (SZ(G[v]) > maxK)
		return ~0;
	int ret = 0;
	FOR(i, 0, SZ(G[v]))
		if (!vis[G[v][i]])
			ret |= 1 << i;
	return ret;
}

bool go(int i, int k)
{
	if (k < 0)
		return false;
	
	while (i < SZ(V) and vis[V[i]])
		i++;
	
	if (i == SZ(V))
		return true;
				
	int v = V[i], adj = effectiveDeg(v), sz = PPC(adj);
	
	if (0 < sz and sz <= k)
	{
		FOR(b, 0, SZ(G[v]))
			if (ithBit(adj, b))
				vis[G[v][b]] = true;
				
		if (go(i+1, k - sz))
			return true;
		
		FOR(b, 0, SZ(G[v]))
			if (ithBit(adj, b))
				vis[G[v][b]] = false;
	}
	
	if (sz != 0)
	{
		vis[v] = true;
		k--;
	}
		
	if (go(i+1, k))
		return true;
	
	if (sz != 0)
		vis[v] = false;
	
	return false;
}

int getCoverSize(int k)
{
	int a = 0, b = k+1;
	while (b - a > 1)
	{
		int c = (a + b) / 2;
		if (go(0, c))
		{
			copy(vis, vis+n+1, found);
			b = c;
		}
		else a = c;
		reset(vis);
	}
	return b;
}

auto getVs(int k)
{
	vector <bool> adaptive(n+1, false);	
	copy(found, found+n+1, vis);

	FOR(i, 1, n+1) if (found[i] and SZ(G[i]) <= k)
	{
		vector <int> introduced, released;
		vis[i] = false;
		
		for (int j : G[i]) if (!vis[j])
		{
			vis[j] = true;
			introduced.pb(j);
		}
		
		FOR(j, 1, n+1) if (vis[j] and SZ(G[j]) <= k)
		{
			if (std::all_of(ALL(G[j]), [&](int l) { return vis[l]; }))
			{
				vis[j] = false;
				released.pb(j);
			}
		}
		
		if (SZ(introduced) == SZ(released) + 1)
			for (int j : introduced)
				adaptive[j] = true;
				
		for (int j : introduced)
			vis[j] = false;
		for (int j : released)
			vis[j] = true;
			
		vis[i] = true;
	}
	vector <int> ret;
	FOR(i, 1, n+1)
		if (found[i] or adaptive[i])
			ret.pb(i);
	return ret;
}

void solve()
{
	int m, k;
	scanf ("%d%d%d", &n, &m, &k);

	FOR(i, 0, m)
	{
		int a, b;
		scanf ("%d%d", &a, &b);
		G[a].pb(b);
		G[b].pb(a);
	}
	
	FOR(i, 1, n+1)
		if (!G[i].empty())
			dedup(G[i]), V.pb(i);
	sort(ALL(V), [&](int a, int b) { return SZ(G[a]) > SZ(G[b]); });
	
	int sz = getCoverSize(k);
	
	if (sz > k)
		printf("-1\n");
	else
	{
		auto vs = getVs(sz);
		printf("%d %d\n", sz, SZ(vs));
		for (int v : vs)
			printf("%d ", v);
		printf("\n");
	}
	
	V.clear();	
	reset(found);
	reset(vis);
	FOR(i, 1, n+1)
		G[i].clear(), G[i].shrink_to_fit();
}
 
int main()
{
	int t = 1;
	scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}