using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var max = 1_000_000_000_000_000; var dlist = new List(); for (var i = 1L; i * i <= max; i += 2) dlist.Add(i * i); var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var c = NList; var (l, r) = (c[0], c[1]); ans[u] = (Count(r, dlist) - Count(l - 1, dlist)) % 2; } WriteLine(string.Join("\n", ans)); } static long Count(long val, List list) { var org = val; var ans = 0L; while (val > 0) { ans += _Count(val, list); val >>= 1; } return ans; } static int _Count(long val, List list) { if (val < list[0]) return 0; var ok = 0; var ng = list.Count; while (ng - ok > 1) { var mid = (ok + ng) / 2; if (list[mid] <= val) ok = mid; else ng = mid; } return ok + 1; } }