Tree to matrix thing