#include
using namespace std;
struct edge { int t; edge *next; };
const int maxn = 100009;
int n, m, ind[maxn], hp[maxn], q[maxn]; edge ebuf_arr[maxn], *ebuf, *head[maxn];
inline void addEdge(int u, int v) { ebuf-> t = v; ebuf-> next = head[u]; head[u] = ebuf ++; }
void sov() { memset(ind, 0, sizeof(ind)); memset(head, 0, sizeof(head)); ebuf = ebuf_arr; scanf("%d%d", &n, &m); for (int i = 0; i < m; ++ i) { int u, v; scanf("%d%d", &u, &v); addEdge(v, u); ++ ind[u]; } int th(0), tq(0); for (int i = 1; i <= n; ++ i) if (!ind[i]) hp[th ++] = i; make_heap(hp, hp + th); while (th) { int p(hp[0]); pop_heap(hp, hp + th –); q[tq ++] = p; for (edge* e = head[p]; e; e = e-> next) { – ind[e-> t]; if (!ind[e-> t]) { hp[th] = e-> t; push_heap(hp, hp + ++ th); } } } if (tq == n) { for (int i = tq - 1; i >= 0; – i) printf("%d “, q[i]); putchar(10); } else puts(“Impossible!”); }
int main() { #ifndef ONLINE_JUDGE freopen(".in”, “r”, stdin); #endif
int t;
scanf("%d", &t);
while (t --)
sov();
}