Tesla reports surprise $312 million profit in Q3