Reconciling 529 Disbursement with Medical Costs Claimed for Special Education

I have a dependent with a learning disability and a written diagnosis from a medical doctor.  As a result, we have significant costs for long-term medical treatment in the form of a tuition for her High School, which specializes in her learning disability. We’ve also withdrawn $10,000 from her 529 to help with those costs.  In order not to double claim expenses on our 2022 return and to avoid a penalty on the 529 distribution, I’ve reduced the medical costs associated with the tuition on our return by the earnings (block 2) reported on the 1099Q. 

 

Should I have reduced the medical costs of the tuition by the entire $10,000 of the 529 distribution, instead?  I did not include the cost basis (block 3) of the 1099Q, because the contribution was made after taxes.  As much as I do not wish to double claim an expense, I do not think it fair to be taxed twice on the cost basis.  If you advise otherwise, please provide the rationale that counters my reasoning.  Thanks.