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
#include <bits/stdc++.h>
#include <random>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>
#define ld long double
#define ull unsigned long long
#define mt make_tuple
    
using namespace std;

const int nax = 1005;
vector<int> adj[nax];
int n, m, k;
bool possible_in_opt[nax];
int min_VC;
bool blocked[nax];
int deg[nax];
vector<pii> unik;

void update(int killed){
    for(pii cur : unik){
        if(!blocked[cur.st] && !blocked[cur.nd]) return;
    }
    if(killed < min_VC){
        min_VC = killed;
        for(int i=1;i<=n;i++) possible_in_opt[i] = blocked[i];
    }
    else if(killed == min_VC){
        for(int i=1;i<=n;i++) possible_in_opt[i] |= blocked[i];
    }
}

void zablokuj(int v){
    blocked[v] = true;
    for(int x : adj[v]){
        deg[x]--;
    }
}

void odblokuj(int v){
    blocked[v] = false;
    for(int x : adj[v]){
        deg[x]++;
    }
}

bool vis[nax];
bool can_exist[nax];
vector<int> living;

void update_pary(int killed){
    for(int i=1;i<=n;i++){
        vis[i] = false;
        can_exist[i] = false;
    }
    int cost = killed;
    for(int i=1;i<=n;i++){
        if(blocked[i]) continue;
        if(!vis[i] && deg[i] < 2){
            living.clear();
            vis[i] = true;
            int tmp = i;
            living.pb(tmp);
            while(1){
                int nxt = -1;
                for(int x : adj[tmp]){
                    if(!vis[x] && !blocked[x]) nxt = x;
                }
                if(nxt == -1) break;
                living.pb(nxt);
                vis[nxt] = true;
                tmp = nxt;
            }
            // path
            int vert = (int)living.size();
            if(vert > 1){
                cost += (vert / 2);
                if(vert & 1){
                    for(int j=1;j<(int)living.size();j+=2){
                        can_exist[living[j]] = true;
                    }
                }
                else{
                    for(int x : living) can_exist[x] = true;
                }
            }
        }
    }

    for(int i=1;i<=n;i++){
        if(!blocked[i] && !vis[i]){
            living.clear();
            vis[i] = true;
            int tmp = i;
            living.pb(tmp);
            while(1){
                int nxt = -1;
                for(int x : adj[tmp]){
                    if(!vis[x] && !blocked[x]) nxt = x;
                }
                if(nxt == -1) break;
                living.pb(nxt);
                vis[nxt] = true;
                tmp = nxt;
            }
            // cycle
            cost += ((int)living.size() + 1) / 2;
            for(int x : living) can_exist[x] = true;
        }
    }

    if(cost < min_VC){
        min_VC = cost;
        for(int i=1;i<=n;i++){
            possible_in_opt[i] = (can_exist[i] || blocked[i]);
        }
    }
    else if(cost == min_VC){
        for(int i=1;i<=n;i++) possible_in_opt[i] |= (can_exist[i] || blocked[i]);
    }
}

void reku(int killed){
    update(killed);
    int mxDeg = -1;
    int cand = -1;
    for(int i=1;i<=n;i++){
        if(!blocked[i] && deg[i] > mxDeg){
            mxDeg = deg[i];
            cand = i;
        }
    }
    if(cand == -1) return;
    if(mxDeg <= 2){
        update_pary(killed);
        return;
    }
    if(killed + 1 <= k){
        zablokuj(cand);
        reku(killed + 1);
        odblokuj(cand);
    }

    vector<int> nei;
    for(int x : adj[cand]){
        if(!blocked[x]) nei.pb(x);
    }

    if(killed + (int)nei.size() <= k && !nei.empty()){
        for(int x : nei) zablokuj(x);
        reku(killed + (int)nei.size());
        for(int x : nei) odblokuj(x);
    }
}

void solve(){
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++) adj[i].clear();
    for(int i=1;i<=n;i++) blocked[i] = false;
    for(int i=1;i<=n;i++) deg[i] = 0;
    for(int i=1;i<=n;i++) possible_in_opt[i] = false;
    min_VC = nax;
    unik.clear();
    vector<pii> edges;
    for(int i=1;i<=m;i++){
        int x, y; cin >> x >> y;
        edges.pb(mp(min(x, y), max(x, y)));
    }
    sort(edges.begin(), edges.end());
    for(int i=0;i<m;i++){
        if(i == 0 || edges[i] != edges[i - 1]){
            int x = edges[i].st;
            int y = edges[i].nd;
            adj[x].pb(y);
            adj[y].pb(x);
            deg[x]++;
            deg[y]++;
            unik.pb(mp(x, y));
        }
    }
    
    reku(0);
    if(min_VC > k){
        cout << -1 << "\n";
        return;
    }
    int cands = 0;
    for(int i=1;i<=n;i++) cands += possible_in_opt[i];
    cout << min_VC << " " << cands << "\n";
    for(int i=1;i<=n;i++){
        if(possible_in_opt[i]) cout << i << " ";
    }
    cout << "\n";
}
    
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int tt = 1;
    cin >> tt;
    while(tt--) solve();
    
    return 0;
}


/*
g++ -std=c++17 -Wall -Wshadow -Wextra -O2 -fsanitize=address -fsanitize=undefined c.cpp -o c
*/