#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1000 + 10;
struct Node {
int to;
};
vector<Node> edge[maxn], edgep[maxn];
int main() {
freopen("input.txt", "r", stdin);
int m, n;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int t2;
Node t;
cin >> t2 >> t.to;
edge[t2].push_back(t);
}
for (int i = 1; i <= n; i++) {
int vis[maxn] = { 0 };
for (vector<Node>::iterator j = edge[i].begin(); j != edge[i].end(); j++) {
Node t = *j;
cout << i << " " << t.to << endl;
if (vis[t.to] == 0) {
edgep[i].push_back(t);
vis[t.to] = 1;
}
}
}
cout << endl;
for (int i = 1; i <= n; i++) {
for (vector<Node>::iterator j = edgep[i].begin(); j != edgep[i].end(); j++) {
Node t = *j;
cout << i << " " << t.to << endl;
}
}
return 0;
}
#include<vector>
using namespace std;
const int maxn = 1000 + 10;
struct Node {
int to;
};
vector<Node> edge[maxn], edgep[maxn];
int main() {
freopen("input.txt", "r", stdin);
int m, n;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int t2;
Node t;
cin >> t2 >> t.to;
edge[t2].push_back(t);
}
for (int i = 1; i <= n; i++) {
int vis[maxn] = { 0 };
for (vector<Node>::iterator j = edge[i].begin(); j != edge[i].end(); j++) {
Node t = *j;
cout << i << " " << t.to << endl;
if (vis[t.to] == 0) {
edgep[i].push_back(t);
vis[t.to] = 1;
}
}
}
cout << endl;
for (int i = 1; i <= n; i++) {
for (vector<Node>::iterator j = edgep[i].begin(); j != edgep[i].end(); j++) {
Node t = *j;
cout << i << " " << t.to << endl;
}
}
return 0;
}