#include <stdio.h>

int main() {
    int num_zones, start_month, start_year, end_month, end_year;
    float eit;

    scanf("%d", &num_zones);
    for (int i = 0; i < num_zones; i++) {
        scanf("%d %d %d %d", &start_month, &start_year, &end_month, &end_year);
        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;
        }
        printf("%0.4f\n", eit);
    }
    return 0;
}