#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> G[N];
int n, m;
int type[N];
int main() {
  ios::sync_with_stdio(0);
  int tt;
  cin >> tt;
  while (tt--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) G[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    vector<int> ans;
    for (int x = 2; x <= n; x++) {
      bool ok[3] = {0, 0, 0};
      for (auto y : G[x]) {
        if (y < x) ok[type[y]] = 1;
      }
      if (!ok[0] && !ok[1])
        type[x] = 0;
      else if (ok[0] && !ok[1])
        type[x] = 1;
      else if (ok[1])
        type[x] = 2, ans.push_back(x);
    }
    cout << ans.size() << endl;
    for (auto e : ans) cout << e << ' ';
    cout << endl;
  }
  return 0;
}
