Problem:
Score : 300 points

Story

I am a Summoner who can invoke monsters. I can embody the pictures of monsters drawn on sketchbooks.

I recently have received a request from Primate Research Institute of Kyoto University to invoke "Hundred Eyes Monster".

What an great honor it is to contribute to the prosperity of the primate research of Kyoto University!
I decided to paint an extremely high-quarity monster to the best of my ability.

I have already painted the forehead and mouth and this time I am going to paint as many eyes as possible between the forehead and mouth.
Well...I cannot wait to see the complete painting.

Problem Statement

Two circles A, B are given on a two-dimensional plane.
The coordinate of the center and radius of circle A is (x_A, y_A) and r_A respectively.
The coordinate of the center and radius of circle B is (x_B, y_B) and r_B respectively.
These two circles have no intersection inside.
Here, we consider a set of circles S that satisfies the following conditions.

Each circle in S touches both A and B, and does not have common points with them inside the circle.

Any two different circles in S have no common points inside them.

Write a program that finds the maximum number of elements in S.

Constraints

1 \leq T \leq 50000

-10^5 \leq x_A \leq 10^5

-10^5 \leq y_A \leq 10^5

-10^5 \leq x_B \leq 10^5

-10^5 \leq y_B \leq 10^5

1 \leq r_A \leq 10^5

1 \leq r_B \leq 10^5

{r_A}^2 + {r_B}^2 < (x_A - x_B)^2 + (y_A - y_B)^2

All values given as input are integers.

It is guaranteed that, when the radiuses of A and B change by 0.0005, the answer does not change.

Input

The input consists of multiple test cases and is given from Standard Input in the following format:

T
testcase_1
:
testcase_T

Each test case is given with the following format.

x_A y_A r_A x_B y_B r_B

Output

The output consists of T lines.
On line i (1 \leq i \leq T), putput the maximum number of elements in S in i-th test case.

Sample Input 1

4
0 -3 2 0 3 2
0 0 9 8 8 2
0 0 9 10 10 5
0 0 707 1000 1000 707

Sample Output 1

3
10
21
180

You can arrange circles ,for example, like the following images in Sample 1, 2.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
//		int Z = 5000000;
//		double[] ras = new double[Z];
//		for(int i = 1;i < Z;i++){
//			ras[i] = (1-Math.sin(Math.PI/i))/(1+Math.sin(Math.PI/i));
//		}
//		tr(ras);
		// c+1/(c-R),c+1/(c+R)
		// c+1/(c+r),c+1/(c-r)
		// 1/(c+R)-1/(c-R)=RB
		// 1/(c-r)-1/(c+r)=RA
		// distance = (sum(c+1/(c+r),c+1/(c-r))-sum(c+1/(c-R),c+1/(c+R)))/2
		// (1/(c+r)+1/(c-r)-1/(c-R)-1/(c+R))/2 = D
		// 2D+RA+RB = 2/(c-r)-2/(c-R)
		// 2D-RA-RB = 2/(c+r)-2/(c+R)
		
		// A-B=RB
		// C-D=RA
		
		// -2R/(c+R)(c-R)=RB
		// 2r/(c+r)(c-r)=RA
		// c/(c+r)(c-r)-c/(c-R)(c+R) = D
		
		for(int T = ni();T > 0;T--){
			double xa = nd();
			double ya = nd();
			double ra = nd();
			double xb = nd();
			double yb = nd();
			double rb = nd();
			if(ra < rb){
				double du = ra; ra = rb; rb = du;
			}
			double D = Point2D.distance(xa, ya, xb, yb);
			// (0,0,ra)
			// (d,0,rb)
			double low = 1e-8, high = 1000000000;
			for(int rep = 0;rep < 100;rep++){
				double c = (low+high)/2;
				// 1/(c+R)-1/(c-R)=2RB=-2R/(c+R)(c-R)
				// c^2*RB-R^2*RB=-R
				// 1/(c-r)-1/(c+r)=2RA=2r/(c+r)(c-r)
				// c^2*RA-r^2*RA=2r
				// (1/(c+r)+1/(c-r)-1/(c-R)-1/(c+R))/2 = D
				double R = (1+Math.sqrt(1+4*rb*rb*c*c))/2/rb;
				double r = (-1+Math.sqrt(1+4*ra*ra*c*c))/2/ra;
//				tr(c, r < c, c < R, (1./(c+r)+1./(c-r)-1./(c-R)-1./(c+R))/2-D);
				double comp = (1./(c+r)+1./(c-r)-1./(c-R)-1./(c+R))/2-D;
				if(comp > 0){
					low = c;
				}else{
					high = c;
				}
			}
			double c = low;
			double R = (1+Math.sqrt(1+4*rb*rb*c*c))/2/rb;
			double r = (-1+Math.sqrt(1+4*ra*ra*c*c))/2/ra;
//			tr((1./(c+r)+1./(c-r)-1./(c-R)-1./(c+R))/2);
			
			double ratio = r/R;
			
			long llow = 2, lhigh = 1000000000000000L;
			while(lhigh - llow > 1){
				long lh = lhigh+llow>>1;
				double si = Math.sin(Math.PI/lh);
				double rz = (1-si)/(1+si);
				if(rz < ratio){
					llow = lh;
				}else{
					lhigh = lh;
				}
			}
			out.println(llow);
		}
	}
	
	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static boolean eof()
	{
		if(lenbuf == -1)return true;
		int lptr = ptrbuf;
		while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
		
		try {
			is.mark(1000);
			while(true){
				int b = is.read();
				if(b == -1){
					is.reset();
					return true;
				}else if(!isSpaceChar(b)){
					is.reset();
					return false;
				}
			}
		} catch (IOException e) {
			return true;
		}
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}