the tests are for a qualifying child
really it boils down to 1 test - where did the child live
both grandparents and mother meet the relationship test
the age test is met -under 19
the support test is whether the child provide more than 1/2 his/her own support which is obviously no (the support provided by the grandparents/mother is not the test). so this test is met
- the Child had the same principal abode as taxpayer for more than ½ the tax year. (nights)
as you can see custody doesn't matter it where the child lived for more than 1/2 the year.
since there are 365 nights in a year, the 1/2 year test can only me met by one party unless they all lived together in teh same house for more than 1/2 the year
now lets say that the child, mother and grandparents lived in the same house more than 1/2 the year. then there is a tiebreaking rule under which the mother wins.