#include <bits/stdc++.h>
using namespace std;
namespace cg {
struct Pt {
  Pt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
  long long x, y;
};
struct Line {
  Line(long long _a = 0, long long _b = 0, long long _c = 0)
      : a(_a), b(_b), c(_c) {}
  long long online(const Pt& p) const { return a * p.x + b * p.y + c; }
  long long a, b, c;
};
inline int dbcmp(double x) {
  if (fabs(x) < 1e-6) return 0;
  return x > 0 ? 1 : -1;
}
inline Pt operator-(const Pt& a, const Pt& b) {
  return Pt(a.x - b.x, a.y - b.y);
}
inline Pt operator+(const Pt& a, const Pt& b) {
  return Pt(a.x + b.x, a.y + b.y);
}
inline long long dot(const Pt& a, const Pt& b) { return a.x * b.x + a.y * b.y; }
inline long long dot(const Pt& a, const Pt& b, const Pt& c) {
  return dot(b - a, c - a);
}
inline long long cross(const Pt& a, const Pt& b) {
  return a.x * b.y - a.y * b.x;
}
inline long long cross(const Pt& a, const Pt& b, const Pt& c) {
  return cross(b - a, c - a);
}
inline long long norm(const Pt& a) { return dot(a, a); }
inline long long norm2(const Pt& a) { return dot(a, a); }
inline double p2l(const Pt& a, const Line& l) {
  return fabs(l.online(a)) / norm(Pt(l.a, l.b));
}
inline Line make_line(const Pt& a, const Pt& b) {
  Line ret;
  ret.a = b.y - a.y;
  ret.b = -(b.x - a.x);
  ret.c = cross(b - a, a);
  return ret;
}
inline Pt get_symmetry(const Pt& a, const Line& l) {
  Pt x(l.a, l.b), y(dot(x, a) + 2 * l.c, cross(x, a));
  double t = norm2(x);
  return Pt(-dot(y, x) / t, -cross(y, x) / t);
}
inline Pt rotate(const Pt& v, double sita) {
  Pt r(cos(sita), -sin(sita));
  return Pt(dot(v, r), -cross(v, r));
}
struct Pt2 {
  Pt A, B;
};
}  // namespace cg
using namespace cg;
int first_condition(Pt2& a, Pt2& b) {
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  swap(b.A, b.B);
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  swap(a.A, a.B);
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  swap(b.A, b.B);
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  return 0;
}
int check(Pt2* data) {
  if (first_condition(data[0], data[1]) == 0) return 0;
  if (dot(data[0].B - data[0].A, data[1].B - data[1].A) < 0 ||
      cross(data[0].B - data[0].A, data[1].B - data[1].A) == 0)
    return 0;
  Line l1 = make_line(data[0].A, data[0].B);
  Line l2 = make_line(data[1].A, data[1].B);
  if (l1.online(data[2].A) != 0 || l2.online(data[2].B) != 0) {
    swap(data[2].A, data[2].B);
    if (l1.online(data[2].A) != 0 || l2.online(data[2].B) != 0) return 0;
  }
  if ((data[2].A.x - data[0].A.x) * (data[2].A.x - data[0].B.x) > 0) return 0;
  if ((data[2].B.x - data[1].A.x) * (data[2].B.x - data[1].B.x) > 0) return 0;
  long long x1 = norm(data[2].A - data[0].A);
  long long x2 = norm(data[2].A - data[0].B);
  long long y1 = norm(data[2].B - data[1].A);
  long long y2 = norm(data[2].B - data[1].B);
  return min(x1, x2) * 16 >= max(x1, x2) && min(y1, y2) * 16 >= max(y1, y2);
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    Pt2 them[3];
    for (int i = 0; i < 3; ++i) {
      cin >> them[i].A.x >> them[i].A.y >> them[i].B.x >> them[i].B.y;
    }
    int ok = 0;
    int perm[3];
    for (int i = 0; i < 3; ++i) perm[i] = i;
    do {
      Pt2 test[3];
      for (int i = 0; i < 3; ++i) test[i] = them[perm[i]];
      if (check(test)) {
        ok = 1;
        break;
      }
    } while (next_permutation(perm, perm + 3));
    puts(ok ? "YES" : "NO");
  }
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

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;
namespace cg {
struct Pt {
  Pt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
  long long x, y;
};
struct Line {
  Line(long long _a = 0, long long _b = 0, long long _c = 0)
      : a(_a), b(_b), c(_c) {}
  long long online(const Pt& p) const { return a * p.x + b * p.y + c; }
  long long a, b, c;
};
inline int dbcmp(double x) {
  if (fabs(x) < 1e-6) return 0;
  return x > 0 ? 1 : -1;
}
inline Pt operator-(const Pt& a, const Pt& b) {
  return Pt(a.x - b.x, a.y - b.y);
}
inline Pt operator+(const Pt& a, const Pt& b) {
  return Pt(a.x + b.x, a.y + b.y);
}
inline long long dot(const Pt& a, const Pt& b) { return a.x * b.x + a.y * b.y; }
inline long long dot(const Pt& a, const Pt& b, const Pt& c) {
  return dot(b - a, c - a);
}
inline long long cross(const Pt& a, const Pt& b) {
  return a.x * b.y - a.y * b.x;
}
inline long long cross(const Pt& a, const Pt& b, const Pt& c) {
  return cross(b - a, c - a);
}
inline long long norm(const Pt& a) { return dot(a, a); }
inline long long norm2(const Pt& a) { return dot(a, a); }
inline double p2l(const Pt& a, const Line& l) {
  return fabs(l.online(a)) / norm(Pt(l.a, l.b));
}
inline Line make_line(const Pt& a, const Pt& b) {
  Line ret;
  ret.a = b.y - a.y;
  ret.b = -(b.x - a.x);
  ret.c = cross(b - a, a);
  return ret;
}
inline Pt get_symmetry(const Pt& a, const Line& l) {
  Pt x(l.a, l.b), y(dot(x, a) + 2 * l.c, cross(x, a));
  double t = norm2(x);
  return Pt(-dot(y, x) / t, -cross(y, x) / t);
}
inline Pt rotate(const Pt& v, double sita) {
  Pt r(cos(sita), -sin(sita));
  return Pt(dot(v, r), -cross(v, r));
}
struct Pt2 {
  Pt A, B;
};
}  // namespace cg
using namespace cg;
int first_condition(Pt2& a, Pt2& b) {
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  swap(b.A, b.B);
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  swap(a.A, a.B);
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  swap(b.A, b.B);
  if (norm(a.A - b.A) == 0 && norm(a.B - b.B) != 0) {
    return 1;
  }
  return 0;
}
int check(Pt2* data) {
  if (first_condition(data[0], data[1]) == 0) return 0;
  if (dot(data[0].B - data[0].A, data[1].B - data[1].A) < 0 ||
      cross(data[0].B - data[0].A, data[1].B - data[1].A) == 0)
    return 0;
  Line l1 = make_line(data[0].A, data[0].B);
  Line l2 = make_line(data[1].A, data[1].B);
  if (l1.online(data[2].A) != 0 || l2.online(data[2].B) != 0) {
    swap(data[2].A, data[2].B);
    if (l1.online(data[2].A) != 0 || l2.online(data[2].B) != 0) return 0;
  }
  if ((data[2].A.x - data[0].A.x) * (data[2].A.x - data[0].B.x) > 0) return 0;
  if ((data[2].B.x - data[1].A.x) * (data[2].B.x - data[1].B.x) > 0) return 0;
  long long x1 = norm(data[2].A - data[0].A);
  long long x2 = norm(data[2].A - data[0].B);
  long long y1 = norm(data[2].B - data[1].A);
  long long y2 = norm(data[2].B - data[1].B);
  return min(x1, x2) * 16 >= max(x1, x2) && min(y1, y2) * 16 >= max(y1, y2);
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    Pt2 them[3];
    for (int i = 0; i < 3; ++i) {
      cin >> them[i].A.x >> them[i].A.y >> them[i].B.x >> them[i].B.y;
    }
    int ok = 0;
    int perm[3];
    for (int i = 0; i < 3; ++i) perm[i] = i;
    do {
      Pt2 test[3];
      for (int i = 0; i < 3; ++i) test[i] = them[perm[i]];
      if (check(test)) {
        ok = 1;
        break;
      }
    } while (next_permutation(perm, perm + 3));
    puts(ok ? "YES" : "NO");
  }
  return 0;
}

```