#include <bits/stdc++.h>
using namespace std;
inline int sign(const double &x) {
  if (fabs(x) < 1E-9) return 0;
  return x < 0 ? -1 : 1;
}
inline int cmpDouble(const double &a, const double &b) { return sign(a - b); }
inline void fixed(double &x) {
  if (fabs(x) < 1E-9) x = 0.0;
}
class Point {
 public:
  double x, y;
  inline Point() {}
  inline Point(const double &x, const double &y) : x(x), y(y) {}
  inline ~Point() {}
  inline void print() const { cout << '(' << x << ',' << y << ')'; }
  inline void println() const { cout << '(' << x << ',' << y << ')' << endl; }
  double length() { return sqrt(x * x + y * y); }
  inline Point operator+(const Point &p) const {
    return Point(x + p.x, y + p.y);
  }
  inline Point operator-(const Point &p) const {
    return Point(x - p.x, y - p.y);
  }
  inline Point operator*(const double &a) const { return Point(a * x, a * y); }
  inline bool operator==(const Point &p) const {
    return cmpDouble(x, p.x) == 0 && cmpDouble(y, p.y) == 0;
  }
  inline bool operator!=(const Point &p) const {
    return cmpDouble(x, p.x) != 0 || cmpDouble(y, p.y) != 0;
  }
};
class Segment {
 public:
  Point s, t;
  inline Segment() {}
  inline Segment(const Point &s, const Point &t) : s(s), t(t) {}
  inline ~Segment() {}
};
double squareDist(const Point &a, const Point &b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
double dist(const Point &a, const Point &b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double dotProduct(const Point &a, const Point &b) {
  return a.x * b.x + a.y * b.y;
}
double crossProduct(const Point &a, const Point &b, const Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
bool isIntersect(const Point &a, const Point &b, const Point &c,
                 const Point &d) {
  return sign(crossProduct(a, b, c) * crossProduct(a, b, d)) < 0 &&
         sign(crossProduct(c, d, a) * crossProduct(c, d, b)) < 0;
}
bool isMiddle(const double &s, const double &m, const double &t) {
  return cmpDouble(s, m) <= 0 && cmpDouble(m, t) <= 0;
}
bool inSegment(const Segment &L, const Point &p) {
  double v = crossProduct(L.s, L.t, p);
  if (sign(v) != 0) return false;
  double minX = min(L.s.x, L.t.x), maxX = max(L.s.x, L.t.x);
  if (!isMiddle(minX, p.x, maxX)) return false;
  double minY = min(L.s.y, L.t.y), maxY = max(L.s.y, L.t.y);
  if (!isMiddle(minY, p.y, maxY)) return false;
  return true;
}
bool isPerfectRatio(const Segment &L, const Point &p) {
  if (L.s == L.t) return false;
  if (L.s == p) return false;
  if (L.t == p) return false;
  double a, b;
  if (L.s.x == L.t.x) {
    a = fabs(p.y - L.s.y);
    b = fabs(L.t.y - p.y);
  } else {
    a = fabs(p.x - L.s.x);
    b = fabs(L.t.x - p.x);
  }
  if (b < a) swap(a, b);
  return cmpDouble(4.0 * a, b) >= 0;
}
bool isA(const Segment &L1, const Segment &L2, const Segment &L3) {
  if (L1.s != L2.s) return false;
  if (!inSegment(L1, L3.s)) return false;
  if (!inSegment(L2, L3.t)) return false;
  double mul = dotProduct(L1.t - L1.s, L2.t - L2.s);
  if (sign(mul) < 0) return false;
  double square = squareDist(L1.s, L1.t) * squareDist(L2.s, L2.t);
  if (cmpDouble(mul * mul, square) == 0) return false;
  return isPerfectRatio(L1, L3.s) && isPerfectRatio(L2, L3.t);
}
bool OK(const Segment &L1, const Segment &L2, const Segment &L3) {
  Segment seg[3];
  for (int i = 0; i < (1 << 3); i++) {
    if (i & 0x1)
      seg[0].s = L1.s, seg[0].t = L1.t;
    else
      seg[0].s = L1.t, seg[0].t = L1.s;
    if (i & 0x2)
      seg[1].s = L2.s, seg[1].t = L2.t;
    else
      seg[1].s = L2.t, seg[1].t = L2.s;
    if (i & 0x4)
      seg[2].s = L3.s, seg[2].t = L3.t;
    else
      seg[2].s = L3.t, seg[2].t = L3.s;
    if (isA(seg[0], seg[1], seg[2])) return true;
  }
  return false;
}
void solve(const int &caseID) {
  int ID[3];
  Segment seg[3];
  for (int i = 0; i < 3; i++) {
    ID[i] = i;
    scanf("%lf %lf %lf %lf", &seg[i].s.x, &seg[i].s.y, &seg[i].t.x,
          &seg[i].t.y);
  }
  bool is = false;
  do {
    if (OK(seg[ID[0]], seg[ID[1]], seg[ID[2]])) {
      is = true;
      break;
    }
  } while (next_permutation(ID, ID + 3));
  if (is)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  ;
  int caseID = 0;
  int T;
  cin >> T;
  while (T--) solve(++caseID);
  return 0;
}

### 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;
inline int sign(const double &x) {
  if (fabs(x) < 1E-9) return 0;
  return x < 0 ? -1 : 1;
}
inline int cmpDouble(const double &a, const double &b) { return sign(a - b); }
inline void fixed(double &x) {
  if (fabs(x) < 1E-9) x = 0.0;
}
class Point {
 public:
  double x, y;
  inline Point() {}
  inline Point(const double &x, const double &y) : x(x), y(y) {}
  inline ~Point() {}
  inline void print() const { cout << '(' << x << ',' << y << ')'; }
  inline void println() const { cout << '(' << x << ',' << y << ')' << endl; }
  double length() { return sqrt(x * x + y * y); }
  inline Point operator+(const Point &p) const {
    return Point(x + p.x, y + p.y);
  }
  inline Point operator-(const Point &p) const {
    return Point(x - p.x, y - p.y);
  }
  inline Point operator*(const double &a) const { return Point(a * x, a * y); }
  inline bool operator==(const Point &p) const {
    return cmpDouble(x, p.x) == 0 && cmpDouble(y, p.y) == 0;
  }
  inline bool operator!=(const Point &p) const {
    return cmpDouble(x, p.x) != 0 || cmpDouble(y, p.y) != 0;
  }
};
class Segment {
 public:
  Point s, t;
  inline Segment() {}
  inline Segment(const Point &s, const Point &t) : s(s), t(t) {}
  inline ~Segment() {}
};
double squareDist(const Point &a, const Point &b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
double dist(const Point &a, const Point &b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double dotProduct(const Point &a, const Point &b) {
  return a.x * b.x + a.y * b.y;
}
double crossProduct(const Point &a, const Point &b, const Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
bool isIntersect(const Point &a, const Point &b, const Point &c,
                 const Point &d) {
  return sign(crossProduct(a, b, c) * crossProduct(a, b, d)) < 0 &&
         sign(crossProduct(c, d, a) * crossProduct(c, d, b)) < 0;
}
bool isMiddle(const double &s, const double &m, const double &t) {
  return cmpDouble(s, m) <= 0 && cmpDouble(m, t) <= 0;
}
bool inSegment(const Segment &L, const Point &p) {
  double v = crossProduct(L.s, L.t, p);
  if (sign(v) != 0) return false;
  double minX = min(L.s.x, L.t.x), maxX = max(L.s.x, L.t.x);
  if (!isMiddle(minX, p.x, maxX)) return false;
  double minY = min(L.s.y, L.t.y), maxY = max(L.s.y, L.t.y);
  if (!isMiddle(minY, p.y, maxY)) return false;
  return true;
}
bool isPerfectRatio(const Segment &L, const Point &p) {
  if (L.s == L.t) return false;
  if (L.s == p) return false;
  if (L.t == p) return false;
  double a, b;
  if (L.s.x == L.t.x) {
    a = fabs(p.y - L.s.y);
    b = fabs(L.t.y - p.y);
  } else {
    a = fabs(p.x - L.s.x);
    b = fabs(L.t.x - p.x);
  }
  if (b < a) swap(a, b);
  return cmpDouble(4.0 * a, b) >= 0;
}
bool isA(const Segment &L1, const Segment &L2, const Segment &L3) {
  if (L1.s != L2.s) return false;
  if (!inSegment(L1, L3.s)) return false;
  if (!inSegment(L2, L3.t)) return false;
  double mul = dotProduct(L1.t - L1.s, L2.t - L2.s);
  if (sign(mul) < 0) return false;
  double square = squareDist(L1.s, L1.t) * squareDist(L2.s, L2.t);
  if (cmpDouble(mul * mul, square) == 0) return false;
  return isPerfectRatio(L1, L3.s) && isPerfectRatio(L2, L3.t);
}
bool OK(const Segment &L1, const Segment &L2, const Segment &L3) {
  Segment seg[3];
  for (int i = 0; i < (1 << 3); i++) {
    if (i & 0x1)
      seg[0].s = L1.s, seg[0].t = L1.t;
    else
      seg[0].s = L1.t, seg[0].t = L1.s;
    if (i & 0x2)
      seg[1].s = L2.s, seg[1].t = L2.t;
    else
      seg[1].s = L2.t, seg[1].t = L2.s;
    if (i & 0x4)
      seg[2].s = L3.s, seg[2].t = L3.t;
    else
      seg[2].s = L3.t, seg[2].t = L3.s;
    if (isA(seg[0], seg[1], seg[2])) return true;
  }
  return false;
}
void solve(const int &caseID) {
  int ID[3];
  Segment seg[3];
  for (int i = 0; i < 3; i++) {
    ID[i] = i;
    scanf("%lf %lf %lf %lf", &seg[i].s.x, &seg[i].s.y, &seg[i].t.x,
          &seg[i].t.y);
  }
  bool is = false;
  do {
    if (OK(seg[ID[0]], seg[ID[1]], seg[ID[2]])) {
      is = true;
      break;
    }
  } while (next_permutation(ID, ID + 3));
  if (is)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  ;
  int caseID = 0;
  int T;
  cin >> T;
  while (T--) solve(++caseID);
  return 0;
}

```