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
#include <bits/stdc++.h>
#define dbg(x) " [" << #x << ": " << (x) << "] "
using namespace std;
template<typename A, typename B>
ostream& operator<<(ostream& out, const pair<A,B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& c) {
    out << "{";
    for(auto it = c.begin(); it != c.end(); it++) {
        if(it != c.begin()) out << ", ";
        out << *it;
    }
    return out << "}";
}
struct Test {
    int n,m,k;
    vector<int> u;
    int mn;
    vector<int> in_ans;
    vector<int> us;
    int cnt;
    vector<int> ord;
    void dfs(const vector<vector<int>>& g, int v) {
        us[v] = 1;
        cnt++;
        ord.push_back(v);
        for(int to : g[v]) {
            if(!us[to]) dfs(g, to);
        }
    }
    void check(const vector<vector<int>>& g, int used, int edges) {
        us.assign(n, 0);
        vector<int> to_add;
        for(int i = 0; i < n; i++) {
            if(!us[i] && g[i].size() == 1) {
                ord.clear();
                cnt = 0;
                dfs(g, i);
                used += cnt / 2;
                if(cnt & 1) {
                    for(int j = 1; j < ord.size(); j += 2) to_add.push_back(ord[j]);
                } else {
                    for(int v : ord) to_add.push_back(v);
                }
            }
        }
        for(int i = 0; i < n; i++) {
            if(!us[i] && g[i].size()) {
                ord.clear();
                cnt = 0;
                dfs(g, i);
                used += (cnt + 1) / 2;
                for(int v : ord) to_add.push_back(v);
            }
        }
        if(used < mn) {
            mn = used;
            in_ans.assign(n, 0);
        }
        if(used == mn) {
            for(int i = 0; i < n; i++) {
                if(u[i] == 2) in_ans[i] = 1;
            }
            for(int i : to_add) in_ans[i] = 1;
        }
    }
    void rec(vector<vector<int>> g, int used, int edges) {
        if(edges == 0) {
            if(used == 0) return;
            if(used < mn) {
                mn = used;
                in_ans.assign(n, 0);
            }
            if(used == mn) {
                for(int i = 0; i < n; i++) {
                    if(u[i] == 2) {
                        in_ans[i] = 1;
                    }
                }
            }
            return;
        }
        if(used >= k || used >= mn) return;
        int j = -1;
        for(int i = 0; i < n; i++) {
            if(u[i]) continue;
            if(j == -1 || g[i].size() > g[j].size()) j = i;
        }
        if(edges > g[j].size() * (k - used)) return;
        if(g[j].size() <= 2) {
            check(g, used, edges);
            return;
        }
        vector<int> nxt = g[j];
        for(int v : nxt) {
            g[v].erase(find(g[v].begin(), g[v].end(), j));
        }
        g[j].clear();
        u[j] = 2;
        edges -= nxt.size();
        rec(g, used + 1, edges);
        u[j] = 1;
        vector<int> in_nxt(n);
        for(int v : nxt) in_nxt[v] = 1;
        vector<vector<int>> g2(n);
        int edges2 = 0;
        for(int i = 0; i < n; i++) {
            if(in_nxt[i]) continue;
            for(int kk : g[i]) {
                if(in_nxt[kk]) continue;
                if(i < kk) edges2++;
                g2[i].push_back(kk);
            }
        }
        for(int v : nxt) {
            u[v] = 2;
        }
        rec(g2, used + nxt.size(), edges2);
        for(int v : nxt) u[v] = 0;
        u[j] = 0;
    }
    void solve() {
        cin >> n >> m >> k;
        set<pair<int,int>> st;
        vector<vector<int>> g(n);
        u.resize(n);
        vector<pair<int,int>> e;
        vector<int> d(n);
        in_ans.resize(n);
        for(int i = 0; i < m; i++) {
            int a,b;
            cin >> a >> b;
            a--;
            b--;
            if(a > b) swap(a, b);
            if(st.find({a,b}) != st.end()) continue;
            st.insert({a,b});
            e.push_back({a,b});
            d[a]++;
            d[b]++;
        }
        int used = 0;
        for(int i = 0; i < n; i++) {
            if(d[i] > k) {
                u[i] = 2;
                in_ans[i] = 1;
                used++;
            }
        }
        int edges = 0;
        for(auto [a,b] : e) {
            if(!in_ans[a] && !in_ans[b]) {
                g[a].push_back(b);
                g[b].push_back(a);
                edges++;
            }
        }
        for(int i = 0; i < n; i++) {
            if(g[i].size() == 0 && !in_ans[i]) u[i] = 1;
        }
        in_ans.assign(n, 0);
        mn = k + 1;
        rec(g, used, edges);
        if(mn == k + 1) {
            cout << -1 << '\n';
            return;
        }
        cout << mn << " ";
        int y = 0;
        for(int i = 0; i < n; i++) y += in_ans[i];
        cout << y << '\n';
        y = 0;
        for(int i = 0; i < n; i++) {
            if(in_ans[i]) {
                if(y) cout << " ";
                cout << i + 1;
                y++;
            }
        }
        cout << '\n';
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int test_num = 1;
    cin >> test_num;
    for(int i = 1; i <= test_num; i++) {
        Test t;
        t.solve();
    }
    return 0;
}