<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

233. The Greatest Angle
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard
output: standard



Consider two points A and B located strictly inside of some circle in Cartesian coordinate system. You task is to find a point C on the circle such that the angle ACB is maximal possible.

Input
On first line of input file there is one integer N - number of tests (1<=N<=10000). I+1-th line describes I-th test case in format X0, Y0, R, XA, YA, XB, YB, where (X0, Y0) is center of the circle, R is radius of the circle, (XA, YA) are point A coordinates, (XB, YB) are point B coordinates. All numbers are integers.
X0, Y0, R are not greater than 10000 by absolute value.

Output
Output file must contain N lines, exactly one for each test case. For each case you must output XC and YC - coordinates of point C, described in statement, with precision of six digits after decimal point. If there are many solutions, output any one of them.

Sample test(s)

Input
2
0 0 2 1 1 -1 1
0 0 2 0 1 1 0

Output
0.000000 2.000000
1.414214 1.414214
Author:	Sergey Simonchik
Resource:	---
Date:	December, 2003

<|response|>
## 1) Abridged problem statement (concise)

For each test case you are given a circle with center \(O=(X_0,Y_0)\) and radius \(R\), and two points \(A,B\) strictly inside it.  
Choose a point \(C\) on the circle such that the angle \(\angle ACB\) is as large as possible. Output any such \(C\) with 6 decimals.

---

## 2) Key observations

1. **Maximizing \(\angle ACB\) ⇔ minimizing circumradius of \(\triangle ABC\)**  
   For a triangle \(ABC\) with circumradius \(\rho\):
   \[
   \sin(\angle ACB)=\frac{|AB|}{2\rho}
   \]
   Since \(|AB|\) is fixed, maximizing \(\angle ACB\) (in \((0,\pi)\)) is equivalent to minimizing \(\rho\).

2. **Centers of circles through \(A\) and \(B\) lie on the perpendicular bisector of \(AB\)**  
   If we shift coordinates so the given circle center is at the origin, then all circumcenters \(P\) of circles passing through \(A,B\) are:
   \[
   P(t)=M+tV
   \]
   where \(M=\frac{A+B}{2}\) and \(V=(B-A)^\perp\).

3. **At the optimum, the circle through \(A,B,C\) is tangent to the given circle**  
   Among circles through \(A,B\) that intersect the given circle, the minimum circumradius occurs at the *boundary* of feasibility—when the intersection becomes tangency.

4. Tangency condition yields a **quadratic equation in \(t\)**, giving up to two candidate circles, hence up to two candidate tangency points \(C\) (actually up to 4 when considering \(\pm\) direction).

---

## 3) Full solution approach

For each test case:

### Step A: Shift coordinates
Let \(O\) be the given circle center. Work with:
\[
A \leftarrow A-O,\quad B \leftarrow B-O
\]
Now the given circle is \(|X|=R\) centered at the origin.

### Step B: Parameterize all circles through \(A\) and \(B\)
Let:
- \(M=\frac{A+B}{2}\)
- \(V=(B-A)^\perp\)
- \(D=|AB|\)

All possible centers are \(P(t)=M+tV\). The radius of this circle is:
\[
\rho(t)=|P(t)-A| = D\sqrt{t^2+\frac14}
\]

### Step C: Enforce tangency with the given circle
Tangency between:
- given circle: center \(0\), radius \(R\)
- candidate circle: center \(P(t)\), radius \(\rho(t)\)

After algebra (as in the editorial/code), you get:
\[
(\,b^2 - 4R^2D^2\,)t^2 + 2bqt + (q^2 - R^2D^2)=0
\]
where:
- \(b = 2(M\cdot V)\)
- \(q = |M|^2 - R^2 - \frac{D^2}{4}\)

Solve this (quadratic or linear degenerate case) to get candidate values of \(t\).

### Step D: Recover tangency point \(C\) for each root
For each candidate \(t\):
1. Compute \(P = M+tV\), \(\rho=D\sqrt{t^2+\frac14}\).
2. Tangency point must lie on the line from origin to \(P\), on the given circle:
   \[
   C = \pm R\frac{P}{|P|}
   \]
3. Check which of the two signs is actually tangent by verifying:
   \[
   |C-P|\approx \rho
   \]

### Step E: Choose the best candidate (maximum angle)
Compute
\[
\cos(\angle ACB)=\frac{(A-C)\cdot(B-C)}{|A-C||B-C|}
\]
Maximizing the angle is equivalent to **minimizing the cosine**. Pick the candidate with smallest cosine.

Finally shift back: \(C \leftarrow C+O\), print.

**Complexity:** \(O(1)\) per test case, suitable for \(N\le 10000\).

---

## 4) C++ implementation (detailed comments)

```cpp
#include <bits/stdc++.h>
using namespace std;

using coord_t = double;

struct Point {
    static constexpr coord_t EPS = 1e-9;
    coord_t x, y;

    Point(coord_t x_=0, coord_t y_=0) : x(x_), y(y_) {}

    Point operator + (const Point& o) const { return {x + o.x, y + o.y}; }
    Point operator - (const Point& o) const { return {x - o.x, y - o.y}; }
    Point operator * (coord_t k)     const { return {x * k, y * k}; }
    Point operator / (coord_t k)     const { return {x / k, y / k}; }

    // dot product
    coord_t dot(const Point& o) const { return x * o.x + y * o.y; }

    // length^2 and length
    coord_t norm2() const { return x*x + y*y; }
    coord_t norm()  const { return sqrt(norm2()); }

    // perpendicular (rotate +90 deg): (x,y) -> (-y,x)
    Point perp() const { return {-y, x}; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    cout << fixed << setprecision(6);

    while (T--) {
        // Input: X0 Y0 R XA YA XB YB
        Point O, A, B;
        coord_t R;
        cin >> O.x >> O.y >> R >> A.x >> A.y >> B.x >> B.y;

        // Shift so circle center becomes origin
        Point Al = A - O;
        Point Bl = B - O;

        // M = midpoint of A,B; V = direction of perpendicular bisector
        Point M = (Al + Bl) / 2.0;
        Point V = (Bl - Al).perp();

        // D = |AB|
        coord_t D = (Bl - Al).norm();
        coord_t Dsq = D * D;

        // Coefficients for tangency quadratic in t
        // b = 2 (M · V)
        coord_t b = 2.0 * M.dot(V);

        // q = |M|^2 - R^2 - D^2/4
        coord_t q = M.norm2() - R*R - Dsq / 4.0;

        // (b^2 - 4 R^2 D^2) t^2 + 2 b q t + (q^2 - R^2 D^2) = 0
        coord_t qa = b*b - 4.0 * R*R * Dsq;
        coord_t qb = 2.0 * b * q;
        coord_t qc = q*q - R*R * Dsq;

        vector<coord_t> ts;

        // Solve quadratic (handle degenerate linear)
        if (fabs(qa) < 1e-18) {
            // qb * t + qc = 0
            if (fabs(qb) > 1e-18) ts.push_back(-qc / qb);
        } else {
            coord_t disc = qb*qb - 4.0*qa*qc;
            if (disc < 0) disc = 0; // clamp numeric noise
            coord_t s = sqrt(disc);
            ts.push_back((-qb + s) / (2.0 * qa));
            ts.push_back((-qb - s) / (2.0 * qa));
        }

        Point bestC;
        coord_t bestCos = 2.0; // cos in [-1,1], so 2 is safely worse

        // Evaluate candidates produced by tangency
        for (coord_t t : ts) {
            // Center of AB-circle at parameter t
            Point P = M + V * t;

            // Its radius rho(t) = D * sqrt(t^2 + 1/4)
            coord_t rho = D * sqrt(t*t + 0.25);

            coord_t pnorm = P.norm();
            if (pnorm < Point::EPS) continue; // direction undefined

            // Tangency point on given circle lies on line OP:
            // C = +/- R * P / |P|
            for (int sign : {+1, -1}) {
                Point C = P * (sign * R / pnorm);

                // Check tangency: C must also lie on circle centered at P of radius rho
                if (fabs((C - P).norm() - rho) > 1e-6) continue;

                // Compute cos(angle ACB)
                Point u = Al - C;
                Point v = Bl - C;
                coord_t nu = u.norm(), nv = v.norm();
                if (nu < Point::EPS || nv < Point::EPS) continue;

                coord_t cosv = u.dot(v) / (nu * nv);

                // larger angle => smaller cos
                if (cosv < bestCos) {
                    bestCos = cosv;
                    bestC = C;
                }
            }
        }

        // Shift answer back
        Point ans = bestC + O;
        cout << ans.x << ' ' << ans.y << "\n";
    }
    return 0;
}
```

---

## 5) Python implementation (detailed comments)

```python
import sys, math

EPS = 1e-9

class Point:
    __slots__ = ("x", "y")
    def __init__(self, x=0.0, y=0.0):
        self.x = float(x)
        self.y = float(y)

    def __add__(self, o): return Point(self.x + o.x, self.y + o.y)
    def __sub__(self, o): return Point(self.x - o.x, self.y - o.y)
    def __mul__(self, k): return Point(self.x * k, self.y * k)   # scalar
    def __truediv__(self, k): return Point(self.x / k, self.y / k)

    def dot(self, o): return self.x * o.x + self.y * o.y
    def norm2(self): return self.x * self.x + self.y * self.y
    def norm(self):  return math.sqrt(self.norm2())

    def perp(self):  # +90 degrees
        return Point(-self.y, self.x)

def solve_case(x0, y0, R, xa, ya, xb, yb):
    O = Point(x0, y0)
    R = float(R)

    # Shift so circle center is origin
    A = Point(xa, ya) - O
    B = Point(xb, yb) - O

    M = (A + B) / 2.0
    V = (B - A).perp()

    D = (B - A).norm()
    Dsq = D * D

    b = 2.0 * M.dot(V)
    q = M.norm2() - R * R - Dsq / 4.0

    qa = b * b - 4.0 * R * R * Dsq
    qb = 2.0 * b * q
    qc = q * q - R * R * Dsq

    ts = []
    if abs(qa) < 1e-18:
        # linear
        if abs(qb) > 1e-18:
            ts.append(-qc / qb)
    else:
        disc = qb * qb - 4.0 * qa * qc
        if disc < 0.0:
            disc = 0.0
        s = math.sqrt(disc)
        ts.append((-qb + s) / (2.0 * qa))
        ts.append((-qb - s) / (2.0 * qa))

    best_cos = 2.0
    bestC = None

    for t in ts:
        P = M + (V * t)
        rho = D * math.sqrt(t * t + 0.25)

        pnorm = P.norm()
        if pnorm < EPS:
            continue

        for sign in (1.0, -1.0):
            C = P * (sign * R / pnorm)

            # Must satisfy tangency: distance to P equals rho
            if abs((C - P).norm() - rho) > 1e-6:
                continue

            u = A - C
            v = B - C
            nu = u.norm()
            nv = v.norm()
            if nu < EPS or nv < EPS:
                continue

            cosv = u.dot(v) / (nu * nv)
            if cosv < best_cos:
                best_cos = cosv
                bestC = C

    # Shift back
    ans = bestC + O
    return ans.x, ans.y

def main():
    data = sys.stdin.buffer.read().split()
    t = int(data[0])
    idx = 1
    out = []

    for _ in range(t):
        x0 = int(data[idx]); y0 = int(data[idx+1]); R = int(data[idx+2])
        xa = int(data[idx+3]); ya = int(data[idx+4])
        xb = int(data[idx+5]); yb = int(data[idx+6])
        idx += 7

        x, y = solve_case(x0, y0, R, xa, ya, xb, yb)
        out.append(f"{x:.6f} {y:.6f}")

    sys.stdout.write("\n".join(out))

if __name__ == "__main__":
    main()
```

Both implementations follow the same geometric idea: reduce to tangency candidates (constant count), evaluate them, and output the best.