#include <bits/stdc++.h>
using namespace std;
using namespace std;
double xx, yy;
struct Point {
  long double x, y;
  Point(long double _x, long double _y) {
    x = _x;
    y = _y;
  }
  Point() {}
  long double mod() { return sqrt(x * x + y * y); }
  long double mod2() { return x * x + y * y; }
  long double arg() { return atan2(y, x); }
  Point ort() { return Point(-y, x); }
  Point rev() { return Point(y, x); }
  Point unit() {
    long double k = mod();
    return Point(x / k, y / k);
  }
  void read() {
    scanf("%lf%lf", &xx, &yy);
    x = xx;
    y = yy;
  }
};
bool operator<(const Point &P1, const Point &P2) {
  return (P1.x != P2.x) ? (P1.x < P2.x) : (P1.y < P2.y);
}
bool operator==(const Point &P1, const Point &P2) {
  return fabs(P1.x - P2.x) < 1e-8 && fabs(P1.y - P2.y) < 1e-8;
}
bool operator>(const Point &P1, const Point &P2) {
  return !(P1 == P2) && !(P1 < P2);
}
bool operator!=(const Point &P1, const Point &P2) { return !(P1 == P2); }
Point operator-(const Point &p1, const Point &p2) {
  return Point(p1.x - p2.x, p1.y - p2.y);
}
Point operator+(const Point &p1, const Point &p2) {
  return Point(p1.x + p2.x, p1.y + p2.y);
}
Point operator*(const Point &p, double k) { return Point(p.x * k, p.y * k); }
Point operator/(const Point &p, double k) { return Point(p.x / k, p.y / k); }
long double dot(const Point &v1, const Point &v2) {
  return v1.x * v2.x + v1.y * v2.y;
}
long double cross(const Point &v1, const Point &v2) {
  return v1.x * v2.y - v1.y * v2.x;
}
long double dis(const Point &P1, const Point &P2) { return (P1 - P2).mod(); }
long double area(const Point &A, const Point &B, const Point &C) {
  return cross(B - A, C - A);
}
struct line {
  Point p1, p2;
  line(Point _p1, Point _p2) {
    p1 = _p1;
    p2 = _p2;
  }
  line() {}
  Point dir() { return p2 - p1; }
  long double mod() { return (p2 - p1).mod(); }
};
bool onSegment(Point P, line L) {
  return fabs(cross(L.dir(), P - L.p1)) < 1e-8 &&
         dot(P - L.p1, P - L.p2) < 1e-8;
}
bool intersects(line L1, line L2) {
  if (onSegment(L1.p1, L2)) return true;
  if (onSegment(L1.p2, L2)) return true;
  if (onSegment(L2.p1, L1)) return true;
  if (onSegment(L2.p2, L1)) return true;
  long double A11 = cross(L1.dir(), L2.p1 - L1.p1);
  long double A12 = cross(L1.dir(), L2.p2 - L1.p1);
  long double A21 = cross(L2.dir(), L1.p1 - L2.p1);
  long double A22 = cross(L2.dir(), L1.p2 - L2.p1);
  if (A11 > 1e-8) swap(A11, A12);
  if (A21 > 1e-8) swap(A21, A22);
  return (A11 < 0 && A12 > 1e-8) && (A21 < 0 && A22 > 1e-8);
}
Point lineIntersection(line S1, line S2) {
  return S1.p1 + S1.dir() * (cross(S2.p1 - S1.p1, S2.dir()) /
                             cross(S1.dir(), S2.dir()));
}
line L[3];
map<Point, int> mapa;
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    Point l, r;
    bool ok = true;
    set<Point> S;
    mapa.clear();
    for (int i = 0; i < 3; i++) {
      l.read();
      r.read();
      if (l == r) ok = false;
      L[i] = line(l, r);
      mapa[l]++;
      mapa[r]++;
      S.insert(l);
      S.insert(r);
    }
    int ct = 0;
    vector<Point> v(S.begin(), S.end());
    for (int i = 0; i < v.size(); i++)
      if (mapa[v[i]] == 2) ct++, l = v[i];
    if (ct != 1)
      puts("NO");
    else {
      for (int i = 0; i < 3; i++)
        if (L[i].p1 != l) swap(L[i].p1, L[i].p2);
      if (L[1].p1 == l) swap(L[0], L[1]);
      if (L[2].p1 == l) swap(L[0], L[2]);
      if (L[2].p1 == l) swap(L[1], L[2]);
      double teta = dot(L[0].p2 - L[0].p1, L[1].p2 - L[1].p1);
      teta /= (L[0].mod() * L[1].mod());
      teta = acos(teta);
      teta = min(teta, 2 * (atan2(0, -1)) - teta);
      if (teta > (atan2(0, -1)) / 2.0 + 1e-8 || abs(teta) < 1e-8) ok = false;
      if (!intersects(L[0], L[2]) || !intersects(L[1], L[2])) ok = false;
      if (onSegment(L[2].p1, L[1]) && onSegment(L[2].p2, L[0]))
        swap(L[2].p1, L[2].p2);
      if (!onSegment(L[2].p1, L[0]) || !onSegment(L[2].p2, L[1])) ok = false;
      if (!ok)
        puts("NO");
      else {
        Point p0 = L[2].p1;
        Point p1 = L[2].p2;
        double l1, l2;
        l1 = (p0 - L[0].p1).mod();
        l2 = (p0 - L[0].p2).mod();
        if (l1 > l2) swap(l1, l2);
        if (4 * l1 + 1e-8 < l2) ok = false;
        l1 = (p1 - L[1].p1).mod();
        l2 = (p1 - L[1].p2).mod();
        if (l1 > l2) swap(l1, l2);
        if (4 * l1 + 1e-8 < l2) ok = false;
        if (ok)
          puts("YES");
        else
          puts("NO");
      }
    }
  }
}

### Prompt

Create a solution in cpp for the following problem:

Little Petya learns how to write. The teacher gave pupils the task to write the letter A on the sheet of paper. It is required to check whether Petya really had written the letter A.

You are given three segments on the plane. They form the letter A if the following conditions hold:

  * Two segments have common endpoint (lets call these segments first and second), while the third segment connects two points on the different segments. 
  * The angle between the first and the second segments is greater than 0 and do not exceed 90 degrees. 
  * The third segment divides each of the first two segments in proportion not less than 1 / 4 (i.e. the ratio of the length of the shortest part to the length of the longest part is not less than 1 / 4). 

Input

The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases to solve. Each case consists of three lines. Each of these three lines contains four space-separated integers — coordinates of the endpoints of one of the segments. All coordinates do not exceed 108 by absolute value. All segments have positive length.

Output

Output one line for each test case. Print «YES» (without quotes), if the segments form the letter A and «NO» otherwise.

Examples

Input

3
4 4 6 0
4 1 5 2
4 0 4 4
0 0 0 6
0 6 2 -4
1 1 0 1
0 0 0 5
0 5 2 -1
1 2 0 1


Output

YES
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
double xx, yy;
struct Point {
  long double x, y;
  Point(long double _x, long double _y) {
    x = _x;
    y = _y;
  }
  Point() {}
  long double mod() { return sqrt(x * x + y * y); }
  long double mod2() { return x * x + y * y; }
  long double arg() { return atan2(y, x); }
  Point ort() { return Point(-y, x); }
  Point rev() { return Point(y, x); }
  Point unit() {
    long double k = mod();
    return Point(x / k, y / k);
  }
  void read() {
    scanf("%lf%lf", &xx, &yy);
    x = xx;
    y = yy;
  }
};
bool operator<(const Point &P1, const Point &P2) {
  return (P1.x != P2.x) ? (P1.x < P2.x) : (P1.y < P2.y);
}
bool operator==(const Point &P1, const Point &P2) {
  return fabs(P1.x - P2.x) < 1e-8 && fabs(P1.y - P2.y) < 1e-8;
}
bool operator>(const Point &P1, const Point &P2) {
  return !(P1 == P2) && !(P1 < P2);
}
bool operator!=(const Point &P1, const Point &P2) { return !(P1 == P2); }
Point operator-(const Point &p1, const Point &p2) {
  return Point(p1.x - p2.x, p1.y - p2.y);
}
Point operator+(const Point &p1, const Point &p2) {
  return Point(p1.x + p2.x, p1.y + p2.y);
}
Point operator*(const Point &p, double k) { return Point(p.x * k, p.y * k); }
Point operator/(const Point &p, double k) { return Point(p.x / k, p.y / k); }
long double dot(const Point &v1, const Point &v2) {
  return v1.x * v2.x + v1.y * v2.y;
}
long double cross(const Point &v1, const Point &v2) {
  return v1.x * v2.y - v1.y * v2.x;
}
long double dis(const Point &P1, const Point &P2) { return (P1 - P2).mod(); }
long double area(const Point &A, const Point &B, const Point &C) {
  return cross(B - A, C - A);
}
struct line {
  Point p1, p2;
  line(Point _p1, Point _p2) {
    p1 = _p1;
    p2 = _p2;
  }
  line() {}
  Point dir() { return p2 - p1; }
  long double mod() { return (p2 - p1).mod(); }
};
bool onSegment(Point P, line L) {
  return fabs(cross(L.dir(), P - L.p1)) < 1e-8 &&
         dot(P - L.p1, P - L.p2) < 1e-8;
}
bool intersects(line L1, line L2) {
  if (onSegment(L1.p1, L2)) return true;
  if (onSegment(L1.p2, L2)) return true;
  if (onSegment(L2.p1, L1)) return true;
  if (onSegment(L2.p2, L1)) return true;
  long double A11 = cross(L1.dir(), L2.p1 - L1.p1);
  long double A12 = cross(L1.dir(), L2.p2 - L1.p1);
  long double A21 = cross(L2.dir(), L1.p1 - L2.p1);
  long double A22 = cross(L2.dir(), L1.p2 - L2.p1);
  if (A11 > 1e-8) swap(A11, A12);
  if (A21 > 1e-8) swap(A21, A22);
  return (A11 < 0 && A12 > 1e-8) && (A21 < 0 && A22 > 1e-8);
}
Point lineIntersection(line S1, line S2) {
  return S1.p1 + S1.dir() * (cross(S2.p1 - S1.p1, S2.dir()) /
                             cross(S1.dir(), S2.dir()));
}
line L[3];
map<Point, int> mapa;
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    Point l, r;
    bool ok = true;
    set<Point> S;
    mapa.clear();
    for (int i = 0; i < 3; i++) {
      l.read();
      r.read();
      if (l == r) ok = false;
      L[i] = line(l, r);
      mapa[l]++;
      mapa[r]++;
      S.insert(l);
      S.insert(r);
    }
    int ct = 0;
    vector<Point> v(S.begin(), S.end());
    for (int i = 0; i < v.size(); i++)
      if (mapa[v[i]] == 2) ct++, l = v[i];
    if (ct != 1)
      puts("NO");
    else {
      for (int i = 0; i < 3; i++)
        if (L[i].p1 != l) swap(L[i].p1, L[i].p2);
      if (L[1].p1 == l) swap(L[0], L[1]);
      if (L[2].p1 == l) swap(L[0], L[2]);
      if (L[2].p1 == l) swap(L[1], L[2]);
      double teta = dot(L[0].p2 - L[0].p1, L[1].p2 - L[1].p1);
      teta /= (L[0].mod() * L[1].mod());
      teta = acos(teta);
      teta = min(teta, 2 * (atan2(0, -1)) - teta);
      if (teta > (atan2(0, -1)) / 2.0 + 1e-8 || abs(teta) < 1e-8) ok = false;
      if (!intersects(L[0], L[2]) || !intersects(L[1], L[2])) ok = false;
      if (onSegment(L[2].p1, L[1]) && onSegment(L[2].p2, L[0]))
        swap(L[2].p1, L[2].p2);
      if (!onSegment(L[2].p1, L[0]) || !onSegment(L[2].p2, L[1])) ok = false;
      if (!ok)
        puts("NO");
      else {
        Point p0 = L[2].p1;
        Point p1 = L[2].p2;
        double l1, l2;
        l1 = (p0 - L[0].p1).mod();
        l2 = (p0 - L[0].p2).mod();
        if (l1 > l2) swap(l1, l2);
        if (4 * l1 + 1e-8 < l2) ok = false;
        l1 = (p1 - L[1].p1).mod();
        l2 = (p1 - L[1].p2).mod();
        if (l1 > l2) swap(l1, l2);
        if (4 * l1 + 1e-8 < l2) ok = false;
        if (ok)
          puts("YES");
        else
          puts("NO");
      }
    }
  }
}

```