#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
bool equal(long double a, long double b) { return abs(a - b) < EPS; }
bool lessOrEqual(long double a, long double b) { return a < b || equal(a, b); }
struct Point {
  long double x, y;
  Point() : x(0), y(0) {}
  Point(long double x, long double y) : x(x), y(y) {}
  bool operator==(const Point &a) const {
    return equal(x, a.x) && equal(y, a.y);
  }
};
istream &operator>>(istream &in, Point &a) {
  in >> a.x >> a.y;
  return in;
}
struct Vector {
  long double x, y;
  Vector() : x(0), y(0) {}
  Vector(long double x, long double y) : x(x), y(y) {}
  Vector(const Point &a, const Point &b) : x(b.x - a.x), y(b.y - a.y) {}
  long double operator*(const Vector &a) const { return x * a.y - y * a.x; }
  long double operator%(const Vector &a) const { return x * a.x + y * a.y; }
  Vector operator*(long double k) const { return {x * k, y * k}; }
  Vector operator/(long double k) const { return {x / k, y / k}; }
  long double len() { return sqrt(*this % *this); }
};
struct Segment {
  Point a, b;
  Segment(Point &a, Point &b) : a(a), b(b) {}
  bool operator==(const Segment &c) const {
    return a == c.a && b == c.b || a == c.b && b == c.a;
  }
  bool operator!=(const Segment &c) const { return !(*this == c); }
};
bool isInLine(const Segment &a, const Point &c) {
  Vector ab(a.a, a.b), ac(a.a, c);
  return equal(ac * ab, 0);
}
bool isInSegment(const Segment &a, const Point &c) {
  Vector ca(c, a.a), cb(c, a.b);
  return isInLine(a, c) && lessOrEqual(ca % cb, 0);
}
bool goodAngle(const Point &a, const Point &b, const Point &c) {
  Vector ba(b, a), bc(b, c);
  return lessOrEqual(0, ba % bc);
}
bool oneSame(const Segment &a, const Segment &b) {
  return a.a == b.a || a.b == b.a || a.a == b.b || a.b == b.b;
}
bool correctSegs(const Segment &a, const Segment &b, const Segment &c) {
  if (!(a != b && a != c && b != c)) {
    return false;
  }
  int cnt = 0;
  cnt += oneSame(a, b);
  cnt += oneSame(b, c);
  cnt += oneSame(a, c);
  return cnt == 1;
}
void sortSegs(Segment &a, Segment &b, Segment &c) {
  if (oneSame(a, c)) {
    swap(b, c);
  }
  if (oneSame(b, c)) {
    swap(a, c);
  }
  bool fl = a.b == b.b;
  if (a.a == b.b || fl) {
    swap(b.a, b.b);
  }
  if (a.b == b.a || fl) {
    swap(a.a, a.b);
  }
  if (!isInSegment(a, c.a)) {
    swap(c.a, c.b);
  }
}
bool checkPos(const Segment &a, const Point &c) {
  Vector ae(a.b, c), eb(c, a.a);
  long double mini = ae.len(), maxi = eb.len();
  if (mini > maxi) {
    swap(mini, maxi);
  }
  return lessOrEqual(0.25, mini / maxi);
}
bool isCorrect(const Segment &a, const Segment &b, const Segment &c) {
  if (!isInSegment(a, c.a) || !isInSegment(b, c.b)) {
    return false;
  }
  if (!goodAngle(a.b, a.a, b.b)) {
    return false;
  }
  return checkPos(a, c.a) && checkPos(b, c.b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int test;
  cin >> test;
  for (int tt = 0; tt < test; ++tt) {
    Point a, b, c, d, e, g;
    cin >> a >> b >> c >> d >> e >> g;
    Segment f(a, b), s(c, d), t(e, g);
    if (!correctSegs(f, s, t)) {
      cout << "NO\n";
      continue;
    }
    sortSegs(f, s, t);
    if (isCorrect(f, s, t)) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}

### Prompt

Develop a solution in Cpp 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;
const long double EPS = 1e-9;
bool equal(long double a, long double b) { return abs(a - b) < EPS; }
bool lessOrEqual(long double a, long double b) { return a < b || equal(a, b); }
struct Point {
  long double x, y;
  Point() : x(0), y(0) {}
  Point(long double x, long double y) : x(x), y(y) {}
  bool operator==(const Point &a) const {
    return equal(x, a.x) && equal(y, a.y);
  }
};
istream &operator>>(istream &in, Point &a) {
  in >> a.x >> a.y;
  return in;
}
struct Vector {
  long double x, y;
  Vector() : x(0), y(0) {}
  Vector(long double x, long double y) : x(x), y(y) {}
  Vector(const Point &a, const Point &b) : x(b.x - a.x), y(b.y - a.y) {}
  long double operator*(const Vector &a) const { return x * a.y - y * a.x; }
  long double operator%(const Vector &a) const { return x * a.x + y * a.y; }
  Vector operator*(long double k) const { return {x * k, y * k}; }
  Vector operator/(long double k) const { return {x / k, y / k}; }
  long double len() { return sqrt(*this % *this); }
};
struct Segment {
  Point a, b;
  Segment(Point &a, Point &b) : a(a), b(b) {}
  bool operator==(const Segment &c) const {
    return a == c.a && b == c.b || a == c.b && b == c.a;
  }
  bool operator!=(const Segment &c) const { return !(*this == c); }
};
bool isInLine(const Segment &a, const Point &c) {
  Vector ab(a.a, a.b), ac(a.a, c);
  return equal(ac * ab, 0);
}
bool isInSegment(const Segment &a, const Point &c) {
  Vector ca(c, a.a), cb(c, a.b);
  return isInLine(a, c) && lessOrEqual(ca % cb, 0);
}
bool goodAngle(const Point &a, const Point &b, const Point &c) {
  Vector ba(b, a), bc(b, c);
  return lessOrEqual(0, ba % bc);
}
bool oneSame(const Segment &a, const Segment &b) {
  return a.a == b.a || a.b == b.a || a.a == b.b || a.b == b.b;
}
bool correctSegs(const Segment &a, const Segment &b, const Segment &c) {
  if (!(a != b && a != c && b != c)) {
    return false;
  }
  int cnt = 0;
  cnt += oneSame(a, b);
  cnt += oneSame(b, c);
  cnt += oneSame(a, c);
  return cnt == 1;
}
void sortSegs(Segment &a, Segment &b, Segment &c) {
  if (oneSame(a, c)) {
    swap(b, c);
  }
  if (oneSame(b, c)) {
    swap(a, c);
  }
  bool fl = a.b == b.b;
  if (a.a == b.b || fl) {
    swap(b.a, b.b);
  }
  if (a.b == b.a || fl) {
    swap(a.a, a.b);
  }
  if (!isInSegment(a, c.a)) {
    swap(c.a, c.b);
  }
}
bool checkPos(const Segment &a, const Point &c) {
  Vector ae(a.b, c), eb(c, a.a);
  long double mini = ae.len(), maxi = eb.len();
  if (mini > maxi) {
    swap(mini, maxi);
  }
  return lessOrEqual(0.25, mini / maxi);
}
bool isCorrect(const Segment &a, const Segment &b, const Segment &c) {
  if (!isInSegment(a, c.a) || !isInSegment(b, c.b)) {
    return false;
  }
  if (!goodAngle(a.b, a.a, b.b)) {
    return false;
  }
  return checkPos(a, c.a) && checkPos(b, c.b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int test;
  cin >> test;
  for (int tt = 0; tt < test; ++tt) {
    Point a, b, c, d, e, g;
    cin >> a >> b >> c >> d >> e >> g;
    Segment f(a, b), s(c, d), t(e, g);
    if (!correctSegs(f, s, t)) {
      cout << "NO\n";
      continue;
    }
    sortSegs(f, s, t);
    if (isCorrect(f, s, t)) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}

```