Write SQL query to solve given problem: How many eastbound trains have rectangular-shaped head cars?. Keep the solution inside sql tag ```sql [SQL-Query] ```
SELECT COUNT(T.train_id) FROM (SELECT T1.train_id FROM cars AS T1 INNER JOIN trains AS T2 ON T1.train_id = T2.id WHERE T1.position = 1 AND T2.direction = 'east' AND T1.shape = 'rectangle' GROUP BY T1.train_id)as T