public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		int t = 1;
		while ((line = in.readLine()) != null && line.length() != 0) {
			int times = Integer.parseInt(line);
			for (int i = 0; i < times; i++) {
				double[] v = readDoubles(in.readLine());
				double la0, lo0, la1, lo1;
				la0 = toR(v[0]);
				lo0 = toR(v[1]);
				la1 = toR(v[2]);
				lo1 = toR(v[3]);
				double disEspheric = disEspherical(la0, lo0, la1, lo1);
				double disTunnel = disTunnel(la0, lo0, la1, lo1);
				long ans = Math.round(Math.abs(disEspheric - disTunnel));
				out.append(ans + "\n");
			}
		}
		System.out.print(out);
	}