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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template <typename A, typename B>
using unordered_map2 = __gnu_pbds::gp_hash_table<A, B>;
using namespace __gnu_pbds;
template <typename T> using ordered_set =
  __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
                   __gnu_pbds::tree_order_statistics_node_update>;
// ordered_set<int> s; s.insert(1); s.insert(2);
// s.order_of_key(1);    // Out: 0.
// *s.find_by_order(1);  // Out: 2.

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, ll b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

constexpr int nax = 1005;

#define RETURN_IF(x) { const int result = x; if (result != -1) return result; }

struct DuzyGraf {
  int n;
  vector<vector<int>> graf;

  int Rozwiaz(int k) {
    #ifdef LOCAL
    debug() << "Rozwiaz(" imie(k) ") {";
    debug() << "  n = " << n;
    for (int i = 0; i < n; i++) {
      debug() << "  graf[" << i << "] = " << graf[i];
    }
    debug() << "}";
    #endif

    assert(0 <= k);
    if (n <= 1) return 0;
    if (n <= 8) return RozwiazBrutalnie(k);
    //cerr << "n = " << n << ", k = " << k << endl;
    RETURN_IF(RozwiazJesliDuzyStopien(k));
    RETURN_IF(RozwiazJesliPuste(k));
    RETURN_IF(RozwiazJesliStopienJeden(k));
    RETURN_IF(RozwiazJesliStopienDwa(k));
    //assert(false or false or false or false);
    return BranczNaNajwiekszymStopniu(k);
  }

  int BranczNaNajwiekszymStopniu(int k) {
    int najw_stop = 0;
    int kto = -1;
    for (int i = 0; i < n; i++) {
      if ((int) graf[i].size() > najw_stop) {
        najw_stop = (int) graf[i].size();
        kto = i;
      }
    }
    assert(3 <= najw_stop and najw_stop <= k);
    const int cotam = RozwiazPoWyborze(k, graf[kto], {kto});
    if (cotam <= k) {
      const int x = RozwiazPoWyborze(cotam - 1, {kto}, {});
      if (x <= cotam - 1) return x;
      return cotam;
    }
    return RozwiazPoWyborze(k, {kto}, {});
  }

  int RozwiazJesliStopienDwa(int k) {
    for (int i = 0; i < n; i++) {
      if ((int) graf[i].size() == 2) {
        const int a = graf[i][0];
        const int b = graf[i][1];
        assert(a != b);
        return RozwiazTrojkacik(k, i, a, b);
      }
    }
    return -1;
  }

  int RozwiazTrojkacik(int k, int v, int a, int b) {
    for (int x : graf[a]) {
      if (x == b) {
        return RozwiazPoWyborze(k, {a, b}, {v});
      }
    }
    vector<bool> wspolne(n);
    for (int s : graf[a]) wspolne[s] = true;
    for (int s : graf[b]) wspolne[s] = true;
    vector<int> remap(n);
    int nast_id = 0;
    for (int i = 0; i < n; i++) {
      if (i == a or i == b) remap[i] = -1;
      else remap[i] = nast_id++;
    }

    assert(nast_id == n - 2);
    DuzyGraf nowy;
    nowy.n = n - 2;
    nowy.graf.resize(n - 2);
    for (int i = 0; i < n; i++) {
      if (i == v) continue;
      const int r = remap[i];
      if (r == -1) continue;
      bool jest_do_v = false;
      for (int s : graf[i]) {
        const int sr = remap[s];
        if (sr == -1) {
          jest_do_v = true;
        } else {
          nowy.graf[r].push_back(sr);
        }
      }
      if (jest_do_v) {
        nowy.graf[r].push_back(remap[v]);
        nowy.graf[remap[v]].push_back(r);
      }
    }
    return nowy.Rozwiaz(k - 1) + 1;
  }

  int RozwiazJesliDuzyStopien(int k) {
    static vector<int> duze;
    int krawedzie = 0;
    for (int i = 0; i < n; i++) {
      if ((int) graf[i].size() > k) {
        duze.push_back(i);
      }
      krawedzie += (int) graf[i].size();
    }
    if (!duze.empty()) {
      vector<int> copy_duze;
      swap(copy_duze, duze);
      return RozwiazPoWyborze(k, copy_duze, {});
    }
    assert(krawedzie % 2 == 0);
    krawedzie /= 2;
    if (krawedzie > k * k) {
      return k + 1;
    }
    return -1;
  }

  int RozwiazJesliStopienJeden(int k) {
    for (int i = 0; i < n; i++) {
      if ((int) graf[i].size() == 1) {
        return RozwiazPoWyborze(k, {graf[i][0]}, {i});
      }
    }
    return -1;
  }

  int RozwiazJesliPuste(int k) {
    static vector<int> puste;
    for (int i = 0; i < n; i++) {
      if (graf[i].empty()) {
        puste.push_back(i);
      }
    }
    if (!puste.empty()) {
      vector<int> copy_puste;
      swap(copy_puste, puste);
      return RozwiazPoWyborze(k, {}, copy_puste);
    }
    return -1;
  }

  int RozwiazPoWyborze(
      int k,
      const vector<int>& biore,
      const vector<int>& wywalam) {
    assert(!biore.empty() or !wywalam.empty());
    if ((int) biore.size() > k) return k + 1;
    vector<int> remap(n, -1);
    for (int b : biore) remap[b] = -2;
    for (int w : wywalam) remap[w] = -3;
    int nast_id = 0;
    for (int i = 0; i < n; i++) {
      int& r = remap[i];
      if (r == -1) r = nast_id++;
    }
    DuzyGraf nowy;
    nowy.n = nast_id;
    nowy.graf.resize(nowy.n);
    for (int i = 0; i < n; i++) {
      const int r = remap[i];
      if (r < 0) continue;
      for (int j : graf[i]) {
        const int rj = remap[j];
        if (rj >= 0) {
          nowy.graf[r].push_back(rj);
        }
      }
    }
    return nowy.Rozwiaz(k - (int) biore.size()) + (int) biore.size();
  }

  int RozwiazBrutalnie(int k) {
    assert(n <= 30);
    int mam_juz = k + 1;
    vector<int> kram(n, 0);
    for (int i = 0; i < n; i++) {
      for (int j : graf[i]) {
        kram[i] |= (1 << j);
      }
    }
    for (int maska = 0; maska < (1 << n); maska++) {
      const int ile = __builtin_popcount(maska);
      if (ile >= mam_juz) continue;
      bool ok = true;
      for (int i = 0; i < n; i++) {
        if ((maska >> i) & 1) {
          continue;
        }
        if ((maska & kram[i]) != kram[i]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        mam_juz = ile;
      }
    }
    assert(0 <= mam_juz);
    return mam_juz;
  }
};

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

  DuzyGraf graf;
  graf.n = n;
  graf.graf.resize(n);

  vector<pair<int, int>> kraw;
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    assert(0 <= a and a < b and b < n);
    kraw.emplace_back(a, b);
  }

  sort(kraw.begin(), kraw.end());
  kraw.erase(unique(kraw.begin(), kraw.end()), kraw.end());

  vector<int> perm(n), perm_rev(n);
  iota(perm.begin(), perm.end(), 0);
  random_shuffle(perm.begin(), perm.end());
  for (int i = 0; i < n; i++) {
    perm_rev[perm[i]] = i;
  }

  for (auto& [a, b] : kraw) {
    a = perm[a];
    b = perm[b];
  }

  for (const auto& [a, b] : kraw) {
    graf.graf[a].push_back(b);
    graf.graf[b].push_back(a);
  }

  const int wynik = graf.Rozwiaz(k);
  assert(0 <= wynik);
  if (wynik > k) {
    cout << -1 << "\n";
    return;
  }
  assert(1 <= wynik);

  vector<int> wierzcholki;
  for (int i = 0; i < n; i++) {
    DuzyGraf nowy;
    nowy.n = n - 1;
    nowy.graf.resize(n - 1);
    for (const auto& kra : kraw) {
      int a = kra.first;
      int b = kra.second;
      if (a == i or b == i) continue;
      if (a > i) a--;
      if (b > i) b--;
      nowy.graf[a].push_back(b);
      nowy.graf[b].push_back(a);
    }
    if (nowy.Rozwiaz(wynik - 1) == wynik - 1) {
      wierzcholki.push_back(perm_rev[i] + 1);
    }
  }

  sort(wierzcholki.begin(), wierzcholki.end());
  assert((int) wierzcholki.size() >= wynik);
  cout << wynik << " " << wierzcholki.size() << "\n";
  for (int i = 0; i < (int) wierzcholki.size(); i++) {
    if (i) cout << " ";
    cout << wierzcholki[i];
  }
  cout << "\n";
}

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

  int t;
  cin >> t;
  while (t--) {
    Przyp();
  }
  return 0;
}