#include <bits/stdc++.h>
using namespace std;
struct Point {
  double x, y;
  Point() : x(0), y(0){};
  Point(double __x, double __y) : x(__x), y(__y){};
};
struct Line {
  Point a, b;
  Line() : a(0, 0), b(0, 0){};
  Line(Point __a, Point __b) : a(__a), b(__b){};
};
struct Vec {
  double x, y;
  Vec() : x(0), y(0){};
  Vec(double __x, double __y) : x(__x), y(__y){};
};
struct Seg {
  Point a, b;
  Seg() : a(0, 0), b(0, 0){};
  Seg(Point __a, Point __b) : a(__a), b(__b){};
};
const double Eps = 1e-9;
const double Inf = 1e+9;
const double pi = 3.14159265358979323846;
double Abs(double t) { return t > 0 ? t : -t; }
int dblcmp(double t) {
  if (Abs(t) < Eps)
    return 0;
  else if (t > 0)
    return 1;
  else
    return -1;
}
double dotdet(Vec a, Vec b) { return a.x * b.x + a.y * b.y; }
double dot(Point a, Point b, Point c) {
  Vec t1(b.x - a.x, b.y - a.y), t2(c.x - a.x, c.y - a.y);
  return dotdet(t1, t2);
}
double det(Vec t1, Vec t2) { return t1.x * t2.y - t2.x * t1.y; }
double cross(Point a, Point b, Point c) {
  Vec t1(b.x - a.x, b.y - a.y), t2(c.x - a.x, c.y - a.y);
  return det(t1, t2);
}
int isIntersect(Seg a, Point b) { return dblcmp(dot(b, a.a, a.b)); }
int isIntersect(Seg a, Seg b, Point &c) {
  double s1, s2, s3, s4;
  int t1, t2, t3, t4;
  t1 = dblcmp(s1 = cross(a.a, a.b, b.a));
  t2 = dblcmp(s2 = cross(a.a, a.b, b.b));
  t3 = dblcmp(s3 = cross(b.a, b.b, a.a));
  t4 = dblcmp(s4 = cross(b.a, b.b, a.b));
  if ((t1 ^ t2) == -2 && (t3 ^ t4) == -2) {
    c.x = (b.a.x * s2 - b.b.x * s1) / (s2 - s1);
    c.y = (b.a.y * s2 - b.b.y * s1) / (s2 - s1);
    return 1;
  } else if ((t1 == 0 && isIntersect(a, b.a) <= 0) ||
             (t2 == 0 && isIntersect(a, b.b) <= 0) ||
             (t3 == 0 && isIntersect(b, a.a) <= 0) ||
             (t4 == 0 && isIntersect(b, a.b) <= 0)) {
    int cnt = 0;
    if (t1 == 0) {
      c = b.a;
      cnt++;
    }
    if (t2 == 0) {
      c = b.b;
      cnt++;
    }
    if (t3 == 0) {
      c = a.a;
      cnt++;
    }
    if (t4 == 0) {
      c = a.b;
      cnt++;
    }
    if (cnt == 1)
      return 2;
    else
      return 1;
  } else
    return 0;
}
double getDis(Point t1, Point t2) {
  return pow((t1.x - t2.x) * (t1.x - t2.x) + (t1.y - t2.y) * (t1.y - t2.y),
             0.5);
}
int main() {
  Seg t1, t2, t3;
  int t, res, i, j, mark1, mark2, yy;
  int num[6][2];
  scanf("%d", &t);
  while (t--) {
    res = 1;
    mark1 = -1;
    for (i = 0; i < 6; i++) scanf("%d%d", &num[i][0], &num[i][1]);
    for (i = 0; i < 5; i++)
      for (j = i + 1; j < 6; j++)
        if (num[i][0] == num[j][0] && num[i][1] == num[j][1]) {
          mark1 = i;
          mark2 = j;
        }
    if (mark1 == -1) {
      printf("NO\n");
      continue;
    }
    t1.a.x = num[mark1][0];
    t1.a.y = num[mark1][1];
    if (mark1 % 2)
      yy = mark1 - 1;
    else
      yy = mark1 + 1;
    t1.b.x = num[yy][0];
    t1.b.y = num[yy][1];
    t2.a.x = num[mark2][0];
    t2.a.y = num[mark2][1];
    if (mark2 % 2)
      yy = mark2 - 1;
    else
      yy = mark2 + 1;
    t2.b.x = num[yy][0];
    t2.b.y = num[yy][1];
    if (mark1 / 2 == 0 && mark2 / 2 == 1) {
      t3.a.x = num[4][0];
      t3.a.y = num[4][1];
      t3.b.x = num[5][0];
      t3.b.y = num[5][1];
    } else if (mark1 / 2 == 0 && mark2 / 2 == 2) {
      t3.a.x = num[2][0];
      t3.a.y = num[2][1];
      t3.b.x = num[3][0];
      t3.b.y = num[3][1];
    } else {
      t3.a.x = num[0][0];
      t3.a.y = num[0][1];
      t3.b.x = num[1][0];
      t3.b.y = num[1][1];
    }
    Vec temp1, temp2;
    temp1.x = t1.b.x - t1.a.x;
    temp1.y = t1.b.y - t1.a.y;
    temp2.x = t2.b.x - t2.a.x;
    temp2.y = t2.b.y - t2.a.y;
    double gg =
        acos(dotdet(temp1, temp2) / (getDis(t1.a, t1.b) * getDis(t2.a, t2.b)));
    if (dblcmp(gg - acos(0)) <= 0 && dblcmp(gg) > 0)
      ;
    else
      res = 0;
    Point temp3;
    if (isIntersect(t1, t3, temp3) == 2) {
      double res1 = getDis(t1.a, temp3), res2 = getDis(temp3, t1.b);
      if (dblcmp(res1) == 0) res = 0;
      if (dblcmp(res2 / res1 - 1.0 / 4) < 0 || dblcmp(res2 / res1 - 4) > 0)
        res = 0;
    } else
      res = 0;
    Point temp4;
    if (isIntersect(t2, t3, temp4) == 2) {
      double res3 = getDis(t2.a, temp4), res4 = getDis(temp4, t2.b);
      if (dblcmp(res3) == 0) res = 0;
      if (dblcmp(res4 / res3 - 1.0 / 4) < 0 || dblcmp(res4 / res3 - 4) > 0)
        res = 0;
    } else
      res = 0;
    if (res)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

### Prompt

Please create a solution in cpp 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;
struct Point {
  double x, y;
  Point() : x(0), y(0){};
  Point(double __x, double __y) : x(__x), y(__y){};
};
struct Line {
  Point a, b;
  Line() : a(0, 0), b(0, 0){};
  Line(Point __a, Point __b) : a(__a), b(__b){};
};
struct Vec {
  double x, y;
  Vec() : x(0), y(0){};
  Vec(double __x, double __y) : x(__x), y(__y){};
};
struct Seg {
  Point a, b;
  Seg() : a(0, 0), b(0, 0){};
  Seg(Point __a, Point __b) : a(__a), b(__b){};
};
const double Eps = 1e-9;
const double Inf = 1e+9;
const double pi = 3.14159265358979323846;
double Abs(double t) { return t > 0 ? t : -t; }
int dblcmp(double t) {
  if (Abs(t) < Eps)
    return 0;
  else if (t > 0)
    return 1;
  else
    return -1;
}
double dotdet(Vec a, Vec b) { return a.x * b.x + a.y * b.y; }
double dot(Point a, Point b, Point c) {
  Vec t1(b.x - a.x, b.y - a.y), t2(c.x - a.x, c.y - a.y);
  return dotdet(t1, t2);
}
double det(Vec t1, Vec t2) { return t1.x * t2.y - t2.x * t1.y; }
double cross(Point a, Point b, Point c) {
  Vec t1(b.x - a.x, b.y - a.y), t2(c.x - a.x, c.y - a.y);
  return det(t1, t2);
}
int isIntersect(Seg a, Point b) { return dblcmp(dot(b, a.a, a.b)); }
int isIntersect(Seg a, Seg b, Point &c) {
  double s1, s2, s3, s4;
  int t1, t2, t3, t4;
  t1 = dblcmp(s1 = cross(a.a, a.b, b.a));
  t2 = dblcmp(s2 = cross(a.a, a.b, b.b));
  t3 = dblcmp(s3 = cross(b.a, b.b, a.a));
  t4 = dblcmp(s4 = cross(b.a, b.b, a.b));
  if ((t1 ^ t2) == -2 && (t3 ^ t4) == -2) {
    c.x = (b.a.x * s2 - b.b.x * s1) / (s2 - s1);
    c.y = (b.a.y * s2 - b.b.y * s1) / (s2 - s1);
    return 1;
  } else if ((t1 == 0 && isIntersect(a, b.a) <= 0) ||
             (t2 == 0 && isIntersect(a, b.b) <= 0) ||
             (t3 == 0 && isIntersect(b, a.a) <= 0) ||
             (t4 == 0 && isIntersect(b, a.b) <= 0)) {
    int cnt = 0;
    if (t1 == 0) {
      c = b.a;
      cnt++;
    }
    if (t2 == 0) {
      c = b.b;
      cnt++;
    }
    if (t3 == 0) {
      c = a.a;
      cnt++;
    }
    if (t4 == 0) {
      c = a.b;
      cnt++;
    }
    if (cnt == 1)
      return 2;
    else
      return 1;
  } else
    return 0;
}
double getDis(Point t1, Point t2) {
  return pow((t1.x - t2.x) * (t1.x - t2.x) + (t1.y - t2.y) * (t1.y - t2.y),
             0.5);
}
int main() {
  Seg t1, t2, t3;
  int t, res, i, j, mark1, mark2, yy;
  int num[6][2];
  scanf("%d", &t);
  while (t--) {
    res = 1;
    mark1 = -1;
    for (i = 0; i < 6; i++) scanf("%d%d", &num[i][0], &num[i][1]);
    for (i = 0; i < 5; i++)
      for (j = i + 1; j < 6; j++)
        if (num[i][0] == num[j][0] && num[i][1] == num[j][1]) {
          mark1 = i;
          mark2 = j;
        }
    if (mark1 == -1) {
      printf("NO\n");
      continue;
    }
    t1.a.x = num[mark1][0];
    t1.a.y = num[mark1][1];
    if (mark1 % 2)
      yy = mark1 - 1;
    else
      yy = mark1 + 1;
    t1.b.x = num[yy][0];
    t1.b.y = num[yy][1];
    t2.a.x = num[mark2][0];
    t2.a.y = num[mark2][1];
    if (mark2 % 2)
      yy = mark2 - 1;
    else
      yy = mark2 + 1;
    t2.b.x = num[yy][0];
    t2.b.y = num[yy][1];
    if (mark1 / 2 == 0 && mark2 / 2 == 1) {
      t3.a.x = num[4][0];
      t3.a.y = num[4][1];
      t3.b.x = num[5][0];
      t3.b.y = num[5][1];
    } else if (mark1 / 2 == 0 && mark2 / 2 == 2) {
      t3.a.x = num[2][0];
      t3.a.y = num[2][1];
      t3.b.x = num[3][0];
      t3.b.y = num[3][1];
    } else {
      t3.a.x = num[0][0];
      t3.a.y = num[0][1];
      t3.b.x = num[1][0];
      t3.b.y = num[1][1];
    }
    Vec temp1, temp2;
    temp1.x = t1.b.x - t1.a.x;
    temp1.y = t1.b.y - t1.a.y;
    temp2.x = t2.b.x - t2.a.x;
    temp2.y = t2.b.y - t2.a.y;
    double gg =
        acos(dotdet(temp1, temp2) / (getDis(t1.a, t1.b) * getDis(t2.a, t2.b)));
    if (dblcmp(gg - acos(0)) <= 0 && dblcmp(gg) > 0)
      ;
    else
      res = 0;
    Point temp3;
    if (isIntersect(t1, t3, temp3) == 2) {
      double res1 = getDis(t1.a, temp3), res2 = getDis(temp3, t1.b);
      if (dblcmp(res1) == 0) res = 0;
      if (dblcmp(res2 / res1 - 1.0 / 4) < 0 || dblcmp(res2 / res1 - 4) > 0)
        res = 0;
    } else
      res = 0;
    Point temp4;
    if (isIntersect(t2, t3, temp4) == 2) {
      double res3 = getDis(t2.a, temp4), res4 = getDis(temp4, t2.b);
      if (dblcmp(res3) == 0) res = 0;
      if (dblcmp(res4 / res3 - 1.0 / 4) < 0 || dblcmp(res4 / res3 - 4) > 0)
        res = 0;
    } else
      res = 0;
    if (res)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

```