#include <bits/stdc++.h>
using namespace std;
struct Point {
  long long x, y;
  double dx, dy;
  bool operator==(Point b) { return x == b.x && y == b.y; }
  Point() {}
  Point(long long cx, long long cy) {
    x = cx;
    y = cy;
  }
};
bool Left(Point &a, Point &b, Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y) > 0;
}
bool LeftOn(Point &a, Point &b, Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y) >= 0;
}
bool Collinear(Point &a, Point &b, Point &c) {
  return ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)) == 0;
}
bool Xor(bool x, bool y) { return !x ^ !y; }
bool IntersectProp(Point &a, Point &b, Point &c, Point &d) {
  if (Collinear(a, b, c) || Collinear(a, b, d) || Collinear(c, d, a) ||
      Collinear(c, d, b))
    return false;
  return Xor(Left(a, b, c), Left(a, b, d)) && Xor(Left(c, d, a), Left(c, d, b));
}
bool Between(Point &a, Point &b, Point &c) {
  if (!Collinear(a, b, c)) return false;
  if (a.x != b.x)
    return ((a.x <= c.x) && (c.x <= b.x)) || ((a.x >= c.x) && (c.x >= b.x));
  else
    return ((a.y <= c.y) && (c.y <= b.y)) || ((a.y >= c.y) && (c.y >= b.y));
}
bool Intersect(Point &a, Point &b, Point &c, Point &d) {
  if (IntersectProp(a, b, c, d))
    return true;
  else if (Between(a, b, c) || Between(a, b, d) || Between(c, d, a) ||
           Between(c, d, b))
    return true;
  else
    return false;
}
vector<pair<Point, Point> > v;
bool ok;
bool an(Point a, Point b, Point c) {
  long long dx1 = b.x - a.x;
  long long dy1 = b.y - a.y;
  long long dx2 = c.x - a.x;
  long long dy2 = c.y - a.y;
  long long d = dx1 * dx2 + dy1 * dy2;
  if (dx1 * dy2 - dx2 * dy1 == 0) return false;
  return d >= 0;
}
double len(Point a, Point b) {
  double dx = (double)a.dx - (double)b.dx;
  double dy = (double)a.dy - (double)b.dy;
  return sqrt(dx * dy + dy * dy);
}
void intersect(Point p1, Point p2, Point p3, Point p4, Point &ret) {
  double vx = p2.x - p1.x;
  double vy = p2.y - p1.y;
  double vbx = p4.x - p3.x;
  double vby = p4.y - p3.y;
  double t = (vby * ((double)p3.x - (double)p1.x) -
              vbx * ((double)p3.y - (double)p1.y)) /
             (vby * vx - vbx * vy);
  ret.dx = (double)p1.x + vx * t;
  ret.dy = (double)p1.y + vy * t;
}
long long sq(Point a, Point p) {
  long long dx = p.x - a.x;
  long long dy = p.y - a.y;
  return dx * dx + dy * dy;
}
bool c1(int a, int b) {
  Point med = v[b].first;
  if (Between(v[a].first, v[a].second, v[b].second)) med = v[b].second;
  long long va = sq(v[a].first, med);
  long long vb = sq(v[a].second, med);
  if (va > vb) swap(va, vb);
  return (va * 16LL >= vb);
}
void solve(int a, int b, int c) {
  if (!an(v[a].first, v[a].second, v[b].second)) return;
  if (!Intersect(v[a].first, v[a].second, v[c].first, v[c].second) ||
      IntersectProp(v[a].first, v[a].second, v[c].first, v[c].second))
    return;
  if (!Intersect(v[b].first, v[b].second, v[c].first, v[c].second) ||
      IntersectProp(v[b].first, v[b].second, v[c].first, v[c].second))
    return;
  if (!c1(a, c)) return;
  if (!c1(b, c)) return;
  ok = true;
}
void check(int a, int b, int c) {
  if (v[a].first == v[b].first || v[a].first == v[b].second) {
    if (v[a].first == v[b].second) {
      swap(v[b].first, v[b].second);
    }
    solve(a, b, c);
    return;
  }
  if (v[a].second == v[b].first || v[a].second == v[b].second) {
    swap(v[a].first, v[a].second);
    if (v[a].first == v[b].second) {
      swap(v[b].first, v[b].second);
    }
    solve(a, b, c);
  }
}
int main() {
  int tst;
  cin >> tst;
  while (tst--) {
    v.clear();
    for (int i = 0; i < 3; i++) {
      Point a, b;
      cin >> a.x >> a.y;
      cin >> b.x >> b.y;
      v.push_back(make_pair(a, b));
    }
    ok = false;
    for (int i = 0; i < 3; i++) {
      for (int j = i + 1; j < 3; j++) {
        if (!IntersectProp(v[i].first, v[i].second, v[j].first, v[j].second) &&
            Intersect(v[i].first, v[i].second, v[j].first, v[j].second)) {
          for (int k = 0; k < 3; k++) {
            if (k == i || k == j) continue;
            check(i, j, k);
          }
        }
      }
    }
    if (!ok)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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;
struct Point {
  long long x, y;
  double dx, dy;
  bool operator==(Point b) { return x == b.x && y == b.y; }
  Point() {}
  Point(long long cx, long long cy) {
    x = cx;
    y = cy;
  }
};
bool Left(Point &a, Point &b, Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y) > 0;
}
bool LeftOn(Point &a, Point &b, Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y) >= 0;
}
bool Collinear(Point &a, Point &b, Point &c) {
  return ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)) == 0;
}
bool Xor(bool x, bool y) { return !x ^ !y; }
bool IntersectProp(Point &a, Point &b, Point &c, Point &d) {
  if (Collinear(a, b, c) || Collinear(a, b, d) || Collinear(c, d, a) ||
      Collinear(c, d, b))
    return false;
  return Xor(Left(a, b, c), Left(a, b, d)) && Xor(Left(c, d, a), Left(c, d, b));
}
bool Between(Point &a, Point &b, Point &c) {
  if (!Collinear(a, b, c)) return false;
  if (a.x != b.x)
    return ((a.x <= c.x) && (c.x <= b.x)) || ((a.x >= c.x) && (c.x >= b.x));
  else
    return ((a.y <= c.y) && (c.y <= b.y)) || ((a.y >= c.y) && (c.y >= b.y));
}
bool Intersect(Point &a, Point &b, Point &c, Point &d) {
  if (IntersectProp(a, b, c, d))
    return true;
  else if (Between(a, b, c) || Between(a, b, d) || Between(c, d, a) ||
           Between(c, d, b))
    return true;
  else
    return false;
}
vector<pair<Point, Point> > v;
bool ok;
bool an(Point a, Point b, Point c) {
  long long dx1 = b.x - a.x;
  long long dy1 = b.y - a.y;
  long long dx2 = c.x - a.x;
  long long dy2 = c.y - a.y;
  long long d = dx1 * dx2 + dy1 * dy2;
  if (dx1 * dy2 - dx2 * dy1 == 0) return false;
  return d >= 0;
}
double len(Point a, Point b) {
  double dx = (double)a.dx - (double)b.dx;
  double dy = (double)a.dy - (double)b.dy;
  return sqrt(dx * dy + dy * dy);
}
void intersect(Point p1, Point p2, Point p3, Point p4, Point &ret) {
  double vx = p2.x - p1.x;
  double vy = p2.y - p1.y;
  double vbx = p4.x - p3.x;
  double vby = p4.y - p3.y;
  double t = (vby * ((double)p3.x - (double)p1.x) -
              vbx * ((double)p3.y - (double)p1.y)) /
             (vby * vx - vbx * vy);
  ret.dx = (double)p1.x + vx * t;
  ret.dy = (double)p1.y + vy * t;
}
long long sq(Point a, Point p) {
  long long dx = p.x - a.x;
  long long dy = p.y - a.y;
  return dx * dx + dy * dy;
}
bool c1(int a, int b) {
  Point med = v[b].first;
  if (Between(v[a].first, v[a].second, v[b].second)) med = v[b].second;
  long long va = sq(v[a].first, med);
  long long vb = sq(v[a].second, med);
  if (va > vb) swap(va, vb);
  return (va * 16LL >= vb);
}
void solve(int a, int b, int c) {
  if (!an(v[a].first, v[a].second, v[b].second)) return;
  if (!Intersect(v[a].first, v[a].second, v[c].first, v[c].second) ||
      IntersectProp(v[a].first, v[a].second, v[c].first, v[c].second))
    return;
  if (!Intersect(v[b].first, v[b].second, v[c].first, v[c].second) ||
      IntersectProp(v[b].first, v[b].second, v[c].first, v[c].second))
    return;
  if (!c1(a, c)) return;
  if (!c1(b, c)) return;
  ok = true;
}
void check(int a, int b, int c) {
  if (v[a].first == v[b].first || v[a].first == v[b].second) {
    if (v[a].first == v[b].second) {
      swap(v[b].first, v[b].second);
    }
    solve(a, b, c);
    return;
  }
  if (v[a].second == v[b].first || v[a].second == v[b].second) {
    swap(v[a].first, v[a].second);
    if (v[a].first == v[b].second) {
      swap(v[b].first, v[b].second);
    }
    solve(a, b, c);
  }
}
int main() {
  int tst;
  cin >> tst;
  while (tst--) {
    v.clear();
    for (int i = 0; i < 3; i++) {
      Point a, b;
      cin >> a.x >> a.y;
      cin >> b.x >> b.y;
      v.push_back(make_pair(a, b));
    }
    ok = false;
    for (int i = 0; i < 3; i++) {
      for (int j = i + 1; j < 3; j++) {
        if (!IntersectProp(v[i].first, v[i].second, v[j].first, v[j].second) &&
            Intersect(v[i].first, v[i].second, v[j].first, v[j].second)) {
          for (int k = 0; k < 3; k++) {
            if (k == i || k == j) continue;
            check(i, j, k);
          }
        }
      }
    }
    if (!ok)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

```