#!/usr/bin/python

# DONE

import re
import sys

rl = sys.stdin.readline

n = int(rl())
assert 1 <= n <= 50

for _ in range(n):
    m1, y1 = map(int, rl().split())
    m2, y2 = map(int, rl().split())
    assert 1 <= m1 <= 12
    assert 1 <= m2 <= 12
    assert y1 >= 0
    assert y2 >= 0

    if y1 < y2:
        eit = 6 + 12 * (y2 - y1 - 1) + m2 - 1
    else:
        assert m1 <= m2
        eit = 6.0 * (m2 - m1) / (13 - m1)

    print '{0:0.4f}'.format(eit / 12.0)

assert not rl()