The expression 'to a T', is often extended to form other phrases: 'down to a T', 'suits to a T', 'fits to a T', 'generous to a T' etc. It is also found in advertising copy like 'Golf to a tee' and 'Coffee to a tea'. Those latter jokey versions are extensions of the alternative spellings 'to a tee' or 'to a tea'. The original form 'to a T' is an old phrase and is first recorded in James Wright's satire The Humours and Conversations of the Town, 1693:
"All the under Villages and Towns-men come to him for Redress; which he does to a T."
http://phrases.org.uk/meanings/to-a-t.html