#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T>
struct Point {
  T x, y;
  Point(T _x = 0, T _y = 0) : x(_x), y(_y) {}
  void read();
  void swap() { swap(x, y); }
  double len() const;
  Point<double> asDouble() { return Point<double>(x, y); }
  Point<T> norm() const;
  Point<T> ort() const { return Point<T>(y, -x); }
};
template <>
void Point<int>::read() {
  scanf("%d%d", &x, &y);
}
template <>
void Point<long long>::read() {
  scanf("%lld%lld", &x, &y);
}
template <>
void Point<double>::read() {
  scanf("%lf%lf", &x, &y);
}
template <typename T>
Point<T> operator-(const Point<T> &a) {
  return Point<T>(-a.x, -a.y);
}
template <typename T>
Point<T> operator+(const Point<T> &a, const Point<T> &b) {
  return Point<T>(a.x + b.x, a.y + b.y);
}
template <typename T>
Point<T> operator-(const Point<T> &a, const Point<T> &b) {
  return Point<T>(a.x - b.x, a.y - b.y);
}
template <typename T>
Point<T> operator*(const T a, const Point<T> &b) {
  return Point<T>(a * b.x, a * b.y);
}
template <typename T>
Point<T> operator*(const Point<T> &b, const T a) {
  return Point<T>(a * b.x, a * b.y);
}
template <typename T>
Point<T> operator/(const Point<T> &b, const T a) {
  return Point<T>(b.x / a, b.y / a);
}
template <typename T>
long long operator*(const Point<T> &a, const Point<T> &b) {
  return a.x * (long long)b.x + a.y * (long long)b.y;
}
template <typename T>
long long operator^(const Point<T> &a, const Point<T> &b) {
  return a.x * (long long)b.y - a.y * (long long)b.x;
}
template <typename T>
double Point<T>::len() const {
  return sqrt((double)((*this) * (*this)));
}
template <typename T>
Point<T> Point<T>::norm() const {
  return (*this) / len();
}
template <typename T>
bool operator<(const Point<T> &a, const Point<T> &b) {
  return a.x < b.x || a.x == b.x && a.y < b.y;
}
bool operator==(const Point<long long> &a, const Point<long long> &b) {
  return a.x == b.x && a.y == b.y;
}
int sign(int x) {
  if (x == 0) return 0;
  if (x > 0)
    return +1;
  else
    return -1;
}
int sign(double x) {
  if (fabs(x) < 1.0e-11) return 0;
  if (x > 0)
    return +1;
  else
    return -1;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
const Point<double> INFDPnt(1.0e30, 1.0e30);
Point<long long> a[3][2];
bool inside(Point<long long> a, Point<long long> b, Point<long long> p) {
  if (((b - a) ^ (p - a)) != 0) return false;
  if (((b - a) * (p - a)) <= 0 || ((a - b) * (p - b)) <= 0) return false;
  long long t = (b - a) * (b - a);
  long long t1 = (p - a) * (p - a);
  long long t2 = (p - b) * (p - b);
  return 25 * t1 >= t && 25 * t2 >= t;
}
bool solve() {
  int ii1 = -1, jj1 = -1, ii2 = -1, jj2 = -1;
  for (int i1 = 0, _n = (3); i1 < _n; i1++)
    for (int j1 = 0, _n = (2); j1 < _n; j1++)
      for (int i2 = 0, _n = (i1); i2 < _n; i2++)
        for (int j2 = 0, _n = (2); j2 < _n; j2++)
          if (a[i1][j1] == a[i2][j2]) {
            if (ii1 != -1) return false;
            ii1 = i1;
            jj1 = j1;
            ii2 = i2;
            jj2 = j2;
          }
  if (ii1 == -1) return false;
  if (ii1 == ii2) return false;
  if (jj1 == 1) swap(a[ii1][0], a[ii1][1]);
  if (jj2 == 1) swap(a[ii2][0], a[ii2][1]);
  int end = 0 + 1 + 2 - ii1 - ii2;
  if (end != 2)
    for (int j = 0, _n = (2); j < _n; j++) swap(a[end][j], a[2][j]);
  Point<long long> p = a[0][0];
  if (((a[0][1] - p) ^ (a[1][1] - p)) == 0) return false;
  if (((a[0][1] - p) * (a[1][1] - p)) < 0) return false;
  return inside(a[0][0], a[0][1], a[2][0]) &&
             inside(a[1][0], a[1][1], a[2][1]) ||
         inside(a[0][0], a[0][1], a[2][1]) && inside(a[1][0], a[1][1], a[2][0]);
}
int main() {
  int tests;
  scanf("%d", &tests);
  for (int test = 1; test <= tests; test++) {
    for (int i = 0, _n = (3); i < _n; i++)
      for (int j = 0, _n = (2); j < _n; j++) a[i][j].read();
    printf("%s\n", solve() ? "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;
const double pi = acos(-1.0);
template <typename T>
struct Point {
  T x, y;
  Point(T _x = 0, T _y = 0) : x(_x), y(_y) {}
  void read();
  void swap() { swap(x, y); }
  double len() const;
  Point<double> asDouble() { return Point<double>(x, y); }
  Point<T> norm() const;
  Point<T> ort() const { return Point<T>(y, -x); }
};
template <>
void Point<int>::read() {
  scanf("%d%d", &x, &y);
}
template <>
void Point<long long>::read() {
  scanf("%lld%lld", &x, &y);
}
template <>
void Point<double>::read() {
  scanf("%lf%lf", &x, &y);
}
template <typename T>
Point<T> operator-(const Point<T> &a) {
  return Point<T>(-a.x, -a.y);
}
template <typename T>
Point<T> operator+(const Point<T> &a, const Point<T> &b) {
  return Point<T>(a.x + b.x, a.y + b.y);
}
template <typename T>
Point<T> operator-(const Point<T> &a, const Point<T> &b) {
  return Point<T>(a.x - b.x, a.y - b.y);
}
template <typename T>
Point<T> operator*(const T a, const Point<T> &b) {
  return Point<T>(a * b.x, a * b.y);
}
template <typename T>
Point<T> operator*(const Point<T> &b, const T a) {
  return Point<T>(a * b.x, a * b.y);
}
template <typename T>
Point<T> operator/(const Point<T> &b, const T a) {
  return Point<T>(b.x / a, b.y / a);
}
template <typename T>
long long operator*(const Point<T> &a, const Point<T> &b) {
  return a.x * (long long)b.x + a.y * (long long)b.y;
}
template <typename T>
long long operator^(const Point<T> &a, const Point<T> &b) {
  return a.x * (long long)b.y - a.y * (long long)b.x;
}
template <typename T>
double Point<T>::len() const {
  return sqrt((double)((*this) * (*this)));
}
template <typename T>
Point<T> Point<T>::norm() const {
  return (*this) / len();
}
template <typename T>
bool operator<(const Point<T> &a, const Point<T> &b) {
  return a.x < b.x || a.x == b.x && a.y < b.y;
}
bool operator==(const Point<long long> &a, const Point<long long> &b) {
  return a.x == b.x && a.y == b.y;
}
int sign(int x) {
  if (x == 0) return 0;
  if (x > 0)
    return +1;
  else
    return -1;
}
int sign(double x) {
  if (fabs(x) < 1.0e-11) return 0;
  if (x > 0)
    return +1;
  else
    return -1;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
const Point<double> INFDPnt(1.0e30, 1.0e30);
Point<long long> a[3][2];
bool inside(Point<long long> a, Point<long long> b, Point<long long> p) {
  if (((b - a) ^ (p - a)) != 0) return false;
  if (((b - a) * (p - a)) <= 0 || ((a - b) * (p - b)) <= 0) return false;
  long long t = (b - a) * (b - a);
  long long t1 = (p - a) * (p - a);
  long long t2 = (p - b) * (p - b);
  return 25 * t1 >= t && 25 * t2 >= t;
}
bool solve() {
  int ii1 = -1, jj1 = -1, ii2 = -1, jj2 = -1;
  for (int i1 = 0, _n = (3); i1 < _n; i1++)
    for (int j1 = 0, _n = (2); j1 < _n; j1++)
      for (int i2 = 0, _n = (i1); i2 < _n; i2++)
        for (int j2 = 0, _n = (2); j2 < _n; j2++)
          if (a[i1][j1] == a[i2][j2]) {
            if (ii1 != -1) return false;
            ii1 = i1;
            jj1 = j1;
            ii2 = i2;
            jj2 = j2;
          }
  if (ii1 == -1) return false;
  if (ii1 == ii2) return false;
  if (jj1 == 1) swap(a[ii1][0], a[ii1][1]);
  if (jj2 == 1) swap(a[ii2][0], a[ii2][1]);
  int end = 0 + 1 + 2 - ii1 - ii2;
  if (end != 2)
    for (int j = 0, _n = (2); j < _n; j++) swap(a[end][j], a[2][j]);
  Point<long long> p = a[0][0];
  if (((a[0][1] - p) ^ (a[1][1] - p)) == 0) return false;
  if (((a[0][1] - p) * (a[1][1] - p)) < 0) return false;
  return inside(a[0][0], a[0][1], a[2][0]) &&
             inside(a[1][0], a[1][1], a[2][1]) ||
         inside(a[0][0], a[0][1], a[2][1]) && inside(a[1][0], a[1][1], a[2][0]);
}
int main() {
  int tests;
  scanf("%d", &tests);
  for (int test = 1; test <= tests; test++) {
    for (int i = 0, _n = (3); i < _n; i++)
      for (int j = 0, _n = (2); j < _n; j++) a[i][j].read();
    printf("%s\n", solve() ? "YES" : "NO");
  }
  return 0;
}

```