#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;
}