#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <string>
using namespace std;
template <typename type>
// 0 means unvisited
// 1 means visited but not finished (still in the stack)
// 2 visited and finished
void DFS( type node, vector<vector<type> > &graph, vector<int> &color,
map<pair<type, type>, string> &types){
color[node] = 1;
// for ( auto edge : types )
// cout << edge.first.first << " " << edge.first.second << " " << edge.second << endl;
// cout << "--------------------------" <<endl;
for( type neighbour : graph[node] ){
if( color[neighbour] == 0 ) {
types[{node, neighbour}] = "Tree";
DFS(neighbour, graph, color, types);
}
else if( color[neighbour] == 1 ) {
types[{node, neighbour}] = "Back";
}
else if( color[neighbour] == 2 ) {
types[{node, neighbour}] = "Forward/Cross";
}
}
color[node] = 2;
}
int main() {
int nodes = 0, edges = 0, cnt = 0;
cin >> nodes >> edges;
vector<vector<int> > graph(nodes);
vector<bool> visited(nodes,false);
vector<int> color(nodes,0), parent(nodes);
map<pair<int, int>, string> types;
for( int node = 0; node < edges; node++ ){
int from, to;
cin >> from >> to;
graph[from].push_back(to);
}
//
// for( int node = 0; node < nodes; node++ ){
// cout << node << " : ";
// for ( auto s : graph[node]) cout << s << " ";
// cout << "\n";
// }
for ( int node = 0; node < nodes; node++ ){
if( color[node] == 0 ) {
DFS(node, graph, color, types);
}
}
for ( auto edge : types )
cout << edge.first.first << " " << edge.first.second << " " << edge.second << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHN0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdGVtcGxhdGUgPHR5cGVuYW1lIHR5cGU+Ci8vIDAgbWVhbnMgdW52aXNpdGVkCi8vIDEgbWVhbnMgdmlzaXRlZCBidXQgbm90IGZpbmlzaGVkIChzdGlsbCBpbiB0aGUgc3RhY2spCi8vIDIgdmlzaXRlZCBhbmQgZmluaXNoZWQKdm9pZCBERlMoIHR5c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