#include <bits/stdc++.h>
const int MAX = 3000;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
using namespace std;
bool eq(long double a, long double b) { return fabsl(a - b) <= EPS; }
struct point {
  long double x, y;
  int id;
  point(long double x = 0, long double y = 0) : x(x), y(y) {}
  point operator+(const point &o) const { return {x + o.x, y + o.y}; }
  point operator-(const point &o) const { return {x - o.x, y - o.y}; }
  point operator*(long double t) const { return {x * t, y * t}; }
  point operator/(long double t) const { return {x / t, y / t}; }
  long double operator*(const point &o) const { return x * o.x + y * o.y; }
  long double operator^(const point &o) const { return x * o.y - y * o.x; }
  bool operator<(const point &o) const {
    if (!eq(x, o.x)) return x < o.x;
    return y < o.y;
  }
  bool operator==(const point &o) const { return eq(x, o.x) and eq(y, o.y); }
};
long double norm(point a) { return sqrt(a * a); }
long double proj(point a, point b) { return a * b / norm(b); }
long double max(long double a, long double b) { return (a > b ? a : b); }
long double min(long double a, long double b) { return (a < b ? a : b); }
long double angle(point a, point b) {
  long double ang = a * b / norm(a) / norm(b);
  return acos(max(min(ang, 1), -1));
}
int ccw(point a, point b, point e) {
  long double tmp = (b - a) ^ (e - a);
  return (tmp > EPS) - (tmp < -EPS);
}
struct line {
  point p1, p2;
  line(point p1 = 0, point p2 = 0) : p1(p1), p2(p2) {}
  long double a = p1.y - p2.y;
  long double b = p2.x - p1.x;
  long double c = -(a * p1.x + b * p1.y);
  bool inside(point p) {
    return eq(norm(p1 - p) + norm(p2 - p) - norm(p2 - p1), 0);
  }
};
point intersect(line l1, line l2) {
  long long det = l1.a * l2.b - l1.b * l2.a;
  if (det == 0) return point(INF, INF);
  long double x = (l1.b * l2.c - l1.c * l2.b) / det;
  long double y = (l1.c * l2.a - l1.a * l2.c) / det;
  return point(x, y);
}
bool check(point a[2], point b[2], point m[2]) {
  if (a[0] == b[1])
    swap(b[0], b[1]);
  else if (a[1] == b[0])
    swap(a[0], a[1]);
  else if (a[1] == b[1]) {
    swap(a[0], a[1]);
    swap(b[0], b[1]);
  } else if (!(a[0] == b[0]))
    return false;
  assert(a[0] == b[0]);
  long double ang = angle(a[1] - a[0], b[1] - b[0]);
  if (ang > PI / 2 + EPS or ang < EPS) return false;
  line A = line(a[0], a[1]);
  line B = line(b[0], b[1]);
  line M = line(m[0], m[1]);
  if (A.inside(m[0]) and B.inside(m[1])) {
    if (norm(a[1] - m[0]) > 4 * norm((m[0] - a[0])) or
        norm(a[0] - m[0]) > 4 * norm((m[0] - a[1])))
      return false;
    if (norm(b[1] - m[1]) > 4 * norm((m[1] - b[0])) or
        norm(b[0] - m[1]) > 4 * norm((m[1] - b[1])))
      return false;
    else
      return true;
  } else if (A.inside(m[1]) and B.inside(m[0])) {
    if (norm(a[1] - m[1]) > 4 * norm((m[1] - a[0])) or
        norm(a[0] - m[1]) > 4 * norm((m[1] - a[1])))
      return false;
    if (norm(b[1] - m[0]) > 4 * norm((m[0] - b[0])) or
        norm(b[0] - m[0]) > 4 * norm((m[0] - b[1])))
      return false;
    else
      return true;
  } else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, x, y;
  cin >> t;
  point vet[3][2];
  while (t--) {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 2; j++) {
        cin >> x >> y;
        vet[i][j] = point(x, y);
      }
    if (check(vet[0], vet[1], vet[2]) or check(vet[0], vet[2], vet[1]) or
        check(vet[1], vet[2], vet[0]))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  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>
const int MAX = 3000;
const long long MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
using namespace std;
bool eq(long double a, long double b) { return fabsl(a - b) <= EPS; }
struct point {
  long double x, y;
  int id;
  point(long double x = 0, long double y = 0) : x(x), y(y) {}
  point operator+(const point &o) const { return {x + o.x, y + o.y}; }
  point operator-(const point &o) const { return {x - o.x, y - o.y}; }
  point operator*(long double t) const { return {x * t, y * t}; }
  point operator/(long double t) const { return {x / t, y / t}; }
  long double operator*(const point &o) const { return x * o.x + y * o.y; }
  long double operator^(const point &o) const { return x * o.y - y * o.x; }
  bool operator<(const point &o) const {
    if (!eq(x, o.x)) return x < o.x;
    return y < o.y;
  }
  bool operator==(const point &o) const { return eq(x, o.x) and eq(y, o.y); }
};
long double norm(point a) { return sqrt(a * a); }
long double proj(point a, point b) { return a * b / norm(b); }
long double max(long double a, long double b) { return (a > b ? a : b); }
long double min(long double a, long double b) { return (a < b ? a : b); }
long double angle(point a, point b) {
  long double ang = a * b / norm(a) / norm(b);
  return acos(max(min(ang, 1), -1));
}
int ccw(point a, point b, point e) {
  long double tmp = (b - a) ^ (e - a);
  return (tmp > EPS) - (tmp < -EPS);
}
struct line {
  point p1, p2;
  line(point p1 = 0, point p2 = 0) : p1(p1), p2(p2) {}
  long double a = p1.y - p2.y;
  long double b = p2.x - p1.x;
  long double c = -(a * p1.x + b * p1.y);
  bool inside(point p) {
    return eq(norm(p1 - p) + norm(p2 - p) - norm(p2 - p1), 0);
  }
};
point intersect(line l1, line l2) {
  long long det = l1.a * l2.b - l1.b * l2.a;
  if (det == 0) return point(INF, INF);
  long double x = (l1.b * l2.c - l1.c * l2.b) / det;
  long double y = (l1.c * l2.a - l1.a * l2.c) / det;
  return point(x, y);
}
bool check(point a[2], point b[2], point m[2]) {
  if (a[0] == b[1])
    swap(b[0], b[1]);
  else if (a[1] == b[0])
    swap(a[0], a[1]);
  else if (a[1] == b[1]) {
    swap(a[0], a[1]);
    swap(b[0], b[1]);
  } else if (!(a[0] == b[0]))
    return false;
  assert(a[0] == b[0]);
  long double ang = angle(a[1] - a[0], b[1] - b[0]);
  if (ang > PI / 2 + EPS or ang < EPS) return false;
  line A = line(a[0], a[1]);
  line B = line(b[0], b[1]);
  line M = line(m[0], m[1]);
  if (A.inside(m[0]) and B.inside(m[1])) {
    if (norm(a[1] - m[0]) > 4 * norm((m[0] - a[0])) or
        norm(a[0] - m[0]) > 4 * norm((m[0] - a[1])))
      return false;
    if (norm(b[1] - m[1]) > 4 * norm((m[1] - b[0])) or
        norm(b[0] - m[1]) > 4 * norm((m[1] - b[1])))
      return false;
    else
      return true;
  } else if (A.inside(m[1]) and B.inside(m[0])) {
    if (norm(a[1] - m[1]) > 4 * norm((m[1] - a[0])) or
        norm(a[0] - m[1]) > 4 * norm((m[1] - a[1])))
      return false;
    if (norm(b[1] - m[0]) > 4 * norm((m[0] - b[0])) or
        norm(b[0] - m[0]) > 4 * norm((m[0] - b[1])))
      return false;
    else
      return true;
  } else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, x, y;
  cin >> t;
  point vet[3][2];
  while (t--) {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 2; j++) {
        cin >> x >> y;
        vet[i][j] = point(x, y);
      }
    if (check(vet[0], vet[1], vet[2]) or check(vet[0], vet[2], vet[1]) or
        check(vet[1], vet[2], vet[0]))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

```