Function to generate the required matrix
function solve ( n ) { let initial_array = new Array ( n - 1 ) ; for ( var i = 0 ; i < initial_array . length ; i ++ ) { initial_array [ i ] = new Array ( 2 ) ; } let final_array = new Array ( n ) ; for ( var i = 0 ; i < final_array . length ; i ++ ) { final_array [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n - 1 ; ++ i ) initial_array [ 0 ] [ i ] = i + 1 ;