#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long LINF = ~(((long long)0x1) << 63) / 2;
template <class T>
bool get_max(T& a, T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, T& b) {
  return b < a ? a = b, 1 : 0;
}
int sgn(double d) { return d > 1e-10 ? 1 : (d < -1e-10 ? -1 : 0); }
inline double sqr(double x) { return x * x; }
int dbcmp(double x, double y) { return sgn(x - y); }
struct point {
  double x, y;
  point(){};
  point(double _x, double _y) {
    x = _x;
    y = _y;
  }
  void input() { scanf("%lf%lf", &x, &y); }
  void output() { printf("%lf %lf", &x, &y); }
  double norm() const { return sqrt(sqr(x) + sqr(y)); }
  double len() { return sqrt(len2()); }
  double len2() { return x * x + y * y; }
  double dis(const point& p) {
    return sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y));
  }
  point trunc(double l) {
    if (sgn(len()) == 0) return *this;
    double r = l / len();
    return point(x * r, y * r);
  }
  point rotate_left() const { return point(-y, x); }
  point rotate_left(double ang) const {
    double c = cos(ang), s = sin(ang);
    return point(x * c - y * s, y * c + x * s);
  }
  point rotate_right() const { return point(y, -x); }
  point rotate_right(double ang) const {
    double c = cos(ang), s = sin(ang);
    return point(x * c + y * s, y * c - x * s);
  }
  point rotate(point p, double angle) {
    point v = *this - p;
    double c = cos(angle), s = sin(angle);
    return point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);
  }
  point unify() { return *this / len(); }
  point operator+(const point& p) { return point(x + p.x, y + p.y); }
  point operator-(const point& p) { return point(x - p.x, y - p.y); }
  point operator*(double r) { return point(x * r, y * r); }
  point operator/(double r) { return point(x / r, y / r); }
  point operator=(const point& p) {
    x = p.x;
    y = p.y;
    return *this;
  }
  bool operator==(const point& p) {
    return sgn(x - p.x) == 0 && sgn(y - p.y) == 0;
  }
  bool operator!=(const point& p) { return !(*this == p); }
  bool operator<(const point& p) {
    return sgn(x - p.x) == 0 ? sgn(y - p.y) < 0 : x < p.x;
  }
  bool operator>(const point& p) {
    return sgn(x - p.x) == 0 ? sgn(y - p.y) > 0 : x > p.x;
  }
  double operator*(point b) { return (x * b.y - y * b.x); }
};
struct line {
  point a, b;
  line() {}
  line(point _a, point _b) {
    a = _a;
    b = _b;
  }
  line operator=(const line& l) {
    a = l.a;
    b = l.b;
    return *this;
  }
  line swap() {
    std::swap(a, b);
    return *this;
  }
};
double dot(point p, point q) { return p.x * q.x + p.y * q.y; }
double xmult(point p1, point p2) { return p1.x * p2.y - p1.y * p2.x; }
double len(point p) { return p.x * p.x + p.y * p.y; }
bool is_online(point p, line l) {
  if (xmult(p - l.a, l.b - l.a) == 0) {
    if (p.x >= min(l.a.x, l.b.x) && p.x <= max(l.a.x, l.b.x) &&
        p.y >= min(l.a.y, l.b.y) && p.y <= max(l.a.y, l.b.y))
      return true;
    else
      return false;
  }
  return false;
}
line l1, l2, l3;
bool check(line l1, line l2, line l3) {
  double re = dot(l1.b - l1.a, l2.b - l2.a);
  if (xmult(l1.b - l1.a, l2.b - l2.a) == 0 || re < 0) return false;
  if (is_online(l3.a, l1) && is_online(l3.b, l2)) {
    double len1 = len(l1.a - l3.a);
    double len2 = len(l1.b - l3.a);
    double mmin = min(len1, len2);
    double mmax = max(len1, len2);
    if (16.0 * mmin - mmax >= 0) {
      len1 = len(l2.a - l3.b);
      len2 = len(l2.b - l3.b);
      mmin = min(len1, len2);
      mmax = max(len1, len2);
      if (16 * mmin - mmax >= 0)
        return true;
      else
        return false;
    } else
      return false;
  } else if (is_online(l3.b, l1) && is_online(l3.a, l2)) {
    double len1 = len(l1.a - l3.b);
    double len2 = len(l1.b - l3.b);
    double mmin = min(len1, len2);
    double mmax = max(len1, len2);
    if (16.0 * mmin - mmax >= 0) {
      len1 = len(l2.a - l3.a);
      len2 = len(l2.b - l3.a);
      mmin = min(len1, len2);
      mmax = max(len1, len2);
      if (16 * mmin - mmax >= 0)
        return true;
      else
        return false;
    } else
      return false;
  } else {
    return false;
  }
}
void solve() {
  int ok1 = 0;
  if (l1.a == l2.a) {
    ok1 = check(l1, l2, l3);
  }
  if (l1.a == l2.b) {
    ok1 = ok1 + check(l1, l2.swap(), l3);
    l2.swap();
  }
  if (l1.b == l2.a) {
    ok1 = ok1 + check(l1.swap(), l2, l3);
    l1.swap();
  }
  if (l1.b == l2.b) {
    ok1 = ok1 + check(l1.swap(), l2.swap(), l3);
    l1.swap();
    l2.swap();
  }
  if (l1.a == l3.a) {
    ok1 = ok1 + check(l1, l3, l2);
  }
  if (l1.a == l3.b) {
    ok1 = ok1 + check(l1, l3.swap(), l2);
    l3.swap();
  }
  if (l1.b == l3.a) {
    ok1 = ok1 + check(l1.swap(), l3, l2);
    l1.swap();
  }
  if (l1.b == l3.b) {
    ok1 = ok1 + check(l1.swap(), l3.swap(), l2);
    l1.swap();
    l3.swap();
  }
  if (l2.a == l3.a) {
    ok1 = ok1 + check(l2, l3, l1);
  }
  if (l2.a == l3.b) {
    ok1 = ok1 + check(l2, l3.swap(), l1);
    l3.swap();
  }
  if (l2.b == l3.a) {
    ok1 = ok1 + check(l2.swap(), l3, l1);
    l2.swap();
  }
  if (l2.b == l3.b) {
    ok1 = ok1 + check(l2.swap(), l3.swap(), l1);
    l2.swap();
    l3.swap();
  }
  if (ok1 > 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> l1.a.x >> l1.a.y >> l1.b.x >> l1.b.y;
    cin >> l2.a.x >> l2.a.y >> l2.b.x >> l2.b.y;
    cin >> l3.a.x >> l3.a.y >> l3.b.x >> l3.b.y;
    solve();
  }
  return 0;
}

### Prompt

Generate a CPP solution to 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;
const int inf = ~0U >> 1;
const long long LINF = ~(((long long)0x1) << 63) / 2;
template <class T>
bool get_max(T& a, T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, T& b) {
  return b < a ? a = b, 1 : 0;
}
int sgn(double d) { return d > 1e-10 ? 1 : (d < -1e-10 ? -1 : 0); }
inline double sqr(double x) { return x * x; }
int dbcmp(double x, double y) { return sgn(x - y); }
struct point {
  double x, y;
  point(){};
  point(double _x, double _y) {
    x = _x;
    y = _y;
  }
  void input() { scanf("%lf%lf", &x, &y); }
  void output() { printf("%lf %lf", &x, &y); }
  double norm() const { return sqrt(sqr(x) + sqr(y)); }
  double len() { return sqrt(len2()); }
  double len2() { return x * x + y * y; }
  double dis(const point& p) {
    return sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y));
  }
  point trunc(double l) {
    if (sgn(len()) == 0) return *this;
    double r = l / len();
    return point(x * r, y * r);
  }
  point rotate_left() const { return point(-y, x); }
  point rotate_left(double ang) const {
    double c = cos(ang), s = sin(ang);
    return point(x * c - y * s, y * c + x * s);
  }
  point rotate_right() const { return point(y, -x); }
  point rotate_right(double ang) const {
    double c = cos(ang), s = sin(ang);
    return point(x * c + y * s, y * c - x * s);
  }
  point rotate(point p, double angle) {
    point v = *this - p;
    double c = cos(angle), s = sin(angle);
    return point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);
  }
  point unify() { return *this / len(); }
  point operator+(const point& p) { return point(x + p.x, y + p.y); }
  point operator-(const point& p) { return point(x - p.x, y - p.y); }
  point operator*(double r) { return point(x * r, y * r); }
  point operator/(double r) { return point(x / r, y / r); }
  point operator=(const point& p) {
    x = p.x;
    y = p.y;
    return *this;
  }
  bool operator==(const point& p) {
    return sgn(x - p.x) == 0 && sgn(y - p.y) == 0;
  }
  bool operator!=(const point& p) { return !(*this == p); }
  bool operator<(const point& p) {
    return sgn(x - p.x) == 0 ? sgn(y - p.y) < 0 : x < p.x;
  }
  bool operator>(const point& p) {
    return sgn(x - p.x) == 0 ? sgn(y - p.y) > 0 : x > p.x;
  }
  double operator*(point b) { return (x * b.y - y * b.x); }
};
struct line {
  point a, b;
  line() {}
  line(point _a, point _b) {
    a = _a;
    b = _b;
  }
  line operator=(const line& l) {
    a = l.a;
    b = l.b;
    return *this;
  }
  line swap() {
    std::swap(a, b);
    return *this;
  }
};
double dot(point p, point q) { return p.x * q.x + p.y * q.y; }
double xmult(point p1, point p2) { return p1.x * p2.y - p1.y * p2.x; }
double len(point p) { return p.x * p.x + p.y * p.y; }
bool is_online(point p, line l) {
  if (xmult(p - l.a, l.b - l.a) == 0) {
    if (p.x >= min(l.a.x, l.b.x) && p.x <= max(l.a.x, l.b.x) &&
        p.y >= min(l.a.y, l.b.y) && p.y <= max(l.a.y, l.b.y))
      return true;
    else
      return false;
  }
  return false;
}
line l1, l2, l3;
bool check(line l1, line l2, line l3) {
  double re = dot(l1.b - l1.a, l2.b - l2.a);
  if (xmult(l1.b - l1.a, l2.b - l2.a) == 0 || re < 0) return false;
  if (is_online(l3.a, l1) && is_online(l3.b, l2)) {
    double len1 = len(l1.a - l3.a);
    double len2 = len(l1.b - l3.a);
    double mmin = min(len1, len2);
    double mmax = max(len1, len2);
    if (16.0 * mmin - mmax >= 0) {
      len1 = len(l2.a - l3.b);
      len2 = len(l2.b - l3.b);
      mmin = min(len1, len2);
      mmax = max(len1, len2);
      if (16 * mmin - mmax >= 0)
        return true;
      else
        return false;
    } else
      return false;
  } else if (is_online(l3.b, l1) && is_online(l3.a, l2)) {
    double len1 = len(l1.a - l3.b);
    double len2 = len(l1.b - l3.b);
    double mmin = min(len1, len2);
    double mmax = max(len1, len2);
    if (16.0 * mmin - mmax >= 0) {
      len1 = len(l2.a - l3.a);
      len2 = len(l2.b - l3.a);
      mmin = min(len1, len2);
      mmax = max(len1, len2);
      if (16 * mmin - mmax >= 0)
        return true;
      else
        return false;
    } else
      return false;
  } else {
    return false;
  }
}
void solve() {
  int ok1 = 0;
  if (l1.a == l2.a) {
    ok1 = check(l1, l2, l3);
  }
  if (l1.a == l2.b) {
    ok1 = ok1 + check(l1, l2.swap(), l3);
    l2.swap();
  }
  if (l1.b == l2.a) {
    ok1 = ok1 + check(l1.swap(), l2, l3);
    l1.swap();
  }
  if (l1.b == l2.b) {
    ok1 = ok1 + check(l1.swap(), l2.swap(), l3);
    l1.swap();
    l2.swap();
  }
  if (l1.a == l3.a) {
    ok1 = ok1 + check(l1, l3, l2);
  }
  if (l1.a == l3.b) {
    ok1 = ok1 + check(l1, l3.swap(), l2);
    l3.swap();
  }
  if (l1.b == l3.a) {
    ok1 = ok1 + check(l1.swap(), l3, l2);
    l1.swap();
  }
  if (l1.b == l3.b) {
    ok1 = ok1 + check(l1.swap(), l3.swap(), l2);
    l1.swap();
    l3.swap();
  }
  if (l2.a == l3.a) {
    ok1 = ok1 + check(l2, l3, l1);
  }
  if (l2.a == l3.b) {
    ok1 = ok1 + check(l2, l3.swap(), l1);
    l3.swap();
  }
  if (l2.b == l3.a) {
    ok1 = ok1 + check(l2.swap(), l3, l1);
    l2.swap();
  }
  if (l2.b == l3.b) {
    ok1 = ok1 + check(l2.swap(), l3.swap(), l1);
    l2.swap();
    l3.swap();
  }
  if (ok1 > 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> l1.a.x >> l1.a.y >> l1.b.x >> l1.b.y;
    cin >> l2.a.x >> l2.a.y >> l2.b.x >> l2.b.y;
    cin >> l3.a.x >> l3.a.y >> l3.b.x >> l3.b.y;
    solve();
  }
  return 0;
}

```