#!/usr/bin/env python
import sys
def eit(startMonth, startYear, endMonth, endYear):
	if (startMonth == endMonth and startYear == endYear): return 0
	elif (startYear == endYear):
		numMonths = endMonth - startMonth
		return (numMonths/(12.-startMonth+1))*0.5
	else:
		numYears = endYear - startYear
		return 0.5 + (numYears - 1) + (endMonth - 1)/12.


if __name__ == "__main__":
	N = int(sys.stdin.readline())
	for i in xrange(N):
		startMonth,startYear = map(int,sys.stdin.readline().strip().split())
		endMonth,endYear = map(int,sys.stdin.readline().strip().split())
		print "%0.4f"%eit(startMonth,startYear,endMonth,endYear)