#include <iostream>
#include <cstdio>
using namespace std;

float EIT(int startMonth, int startYear, int endMonth, int endYear) {
	if (startMonth == endMonth && startYear == endYear) {
		return 0;
	} else if (startYear == endYear) {
		int numMonths = endMonth - startMonth;
		return (numMonths/(12.-startMonth+1))*0.5;
	} else {
		int numYears = endYear - startYear;
		return 0.5 + (numYears-1) + (endMonth - 1)/12.;
	}
}

int main() {
	int n,startMonth,startYear,endMonth,endYear;
	cin >> n;
	while (n-- > 0) {
		cin >> startMonth >> startYear >> endMonth >> endYear;
		printf("%0.4f\n", EIT(startMonth,startYear,endMonth,endYear));
	}
}