T = int(input()) for _ in range(T): n, x = input().split() n = int(n) x = float(x) res = ((x - 1j)**(-n-1) - (x + 1j)**(-n-1)) * (-1)**n / 2j res *= (x**2 + 1)**(n/2 + 1) print(res.real)