#include <stdio.h>
#include <stack>
#include <map>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <functional>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
//#define ld long double
const double sn = 1e-6;
int n, m;
int perm[200005];
int main() {
int t;
scanf("%d", &t);
for (int ii = 0; ii < t; ii++) {
vector<set<int>> adj = {};
adj.push_back({});
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
perm[i] = i;
adj.push_back({});
}
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
adj[b].insert(a);
}
for (int i = 2; i <= n; i++) {
int j = i;
while (j > 1 && adj[i].find(perm[j-1])!=adj[i].end()) {
int temp = perm[j - 1];
perm[j - 1] = i;
perm[j] = temp;
j--;
}
}
for (int i = 1; i <= n; i++) {
printf("%d", perm[i]);
if (i != n)
printf(" ");
}
printf("\n");
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIHBiIHB1c2hfYmFjawovLyNkZWZpbmUgbGQgbG9uZyBkb3VibGUKY29uc3QgZG91YmxlIHNuID0gMWUtNjsKaW50IG4sIG07CmludCBwZXJtWzIwMDAwNV07CgppbnQgbWFpbigpIHsKC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