Flatten term graph for AC terms