Write SQL query to solve given problem: How many students taking a bachelor's degree received an A in all of the courses that they took?. Keep the solution inside sql tag ```sql [SQL-Query] ```
SELECT COUNT(T2.student_id) FROM student AS T1 INNER JOIN registration AS T2 ON T1.student_id = T2.student_id WHERE T2.grade = 'A' AND T1.type = 'UG'