perl -ane'{$g=$F[0] or die"{}\n";print"n=$g;";$q=0;while($q!=2){print"$g";if($g%2==1){$g=$g*3+1;}else{$g=$g/2;}print",";if($g==1){$q++;}}print"1\n";}'

Disclaimer: This is an unofficial UMMS page.