#!/usr/bin/env python
num_zones = input()
for i in xrange(num_zones):
    start_month, start_year = map(int, raw_input().split())
    end_month, end_year = map(int, raw_input().split())
    if start_year == end_year:
        eit = 0.5 * (end_month - start_month) / (13 - start_month)
    else:
        eit = 0.5 + (end_year - start_year - 1) + (end_month - 1) / 12.0
    print '%0.4f' % eit