#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7, M = 2e6;
const long long mod = 1e9 + 7;
inline int read() {
  int ret = 0;
  char ch = getchar();
  bool f = 1;
  for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^ '-');
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - 48;
  return f ? ret : -ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
const double EPS = 1e-15;
inline int sign(double a) { return a < -EPS ? -1 : a > EPS; }
inline int cmp(double a, double b) { return sign(a - b); }
struct P {
  double x, y;
  P() {}
  P(double _x, double _y) : x(_x), y(_y) {}
  P operator+(P p) { return {x + p.x, y + p.y}; }
  P operator-(P p) { return {x - p.x, y - p.y}; }
  P operator*(double d) { return {x * d, y * d}; }
  P operator/(double d) { return {x / d, y / d}; }
  bool operator<(P p) const {
    int c = cmp(x, p.x);
    if (c) return c == -1;
    return cmp(y, p.y) == -1;
  }
  bool operator==(P o) const { return cmp(x, o.x) == 0 && cmp(y, o.y) == 0; }
  void scan() {
    double k1, k2;
    scanf("%lf%lf", &k1, &k2);
    x = k1, y = k2;
  }
  void print() { printf("(%.0f,%.0f)", x, y); }
  double dot(P p) { return x * p.x + y * p.y; }
  double det(P p) { return x * p.y - y * p.x; }
  double distTo(P p) { return (*this - p).abs(); }
  double alpha() { return atan2(y, x); }
  double abs() { return sqrt(abs2()); }
  double abs2() { return x * x + y * y; }
  P rot90() { return P(-y, x); }
  P unit() { return *this / abs(); }
  double distTTo(P p) { return hypot(x - p.x, y - p.y); }
  int quad() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0); }
};
bool isMiddle(double a, double m, double b) {
  return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}
bool isMiddle(P a, P m, P b) {
  return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
}
bool onSeg(P p1, P p2, P q) {
  return sign(((p2.x - p1.x) * (q.y - p1.y) - (q.x - p1.x) * (p2.y - p1.y))) ==
             0 &&
         isMiddle(p1, q, p2);
}
bool onSeg_strict(P p1, P p2, P q) {
  return sign(((p2.x - p1.x) * (q.y - p1.y) - (q.x - p1.x) * (p2.y - p1.y))) ==
             0 &&
         sign((q - p1).dot(p1 - p2)) * sign((q - p2).dot(p1 - p2)) < 0;
}
P p[4][2];
int a, b, c;
pair<int, int> judge() {
  for (int i = 1; i <= 3; i++)
    for (int j = i + 1; j <= 3; j++)
      for (int k = 0; k < 2; k++)
        for (int z = 0; z < 2; z++) {
          if (p[i][k] == p[j][z]) {
            return make_pair(i, j);
          }
        }
  return make_pair(0, 0);
}
bool judge2() {
  int res1 = 0, res2 = 0;
  if (onSeg(p[a][0], p[a][1], p[c][0])) {
    res1 = 1;
  }
  if (onSeg(p[b][0], p[b][1], p[c][0])) {
    if (res1 == 1) return false;
    res1 = 2;
  }
  if (onSeg(p[a][0], p[a][1], p[c][1])) {
    res2 = 1;
    if (res1 == 1) return false;
  }
  if (onSeg(p[b][0], p[b][1], p[c][1])) {
    if (res2 == 1) return false;
    res2 = 2;
    if (res1 == 2) return false;
  }
  if (res1 + res2 != 3) return false;
  double dis1, dis2;
  if (res1 == 1) {
    dis1 = p[c][0].distTo(p[a][0]);
    dis2 = p[c][0].distTo(p[a][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
    dis1 = p[c][1].distTo(p[b][0]);
    dis2 = p[c][1].distTo(p[b][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
  } else {
    dis1 = p[c][0].distTo(p[b][0]);
    dis2 = p[c][0].distTo(p[b][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
    dis1 = p[c][1].distTo(p[a][0]);
    dis2 = p[c][1].distTo(p[a][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
  }
  return true;
}
bool judge3() {
  if (p[a][0] == p[b][0]) {
    if (sign((p[a][0] - p[a][1]).dot(p[a][0] - p[b][1])) < 0) return false;
  } else if (p[a][0] == p[b][1]) {
    if (sign((p[a][0] - p[a][1]).dot(p[a][0] - p[b][0])) < 0) return false;
  } else if (p[a][1] == p[b][0]) {
    if (sign((p[a][1] - p[a][0]).dot(p[a][1] - p[b][1])) < 0) return false;
  } else if (p[a][1] == p[b][1]) {
    if (sign((p[a][1] - p[a][0]).dot(p[a][1] - p[b][0])) < 0) return false;
  }
  return true;
}
int main() {
  int t;
  pair<int, int> res;
  scanf("%d", &t);
  while (t--) {
    p[1][0].scan();
    p[1][1].scan();
    p[2][0].scan();
    p[2][1].scan();
    p[3][0].scan();
    p[3][1].scan();
    res = judge();
    if (res.first == 0) {
      puts("NO");
      continue;
    }
    a = res.first;
    b = res.second;
    c = 6 - a - b;
    if (!judge3()) {
      puts("NO");
      continue;
    }
    if (judge2())
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

### Prompt

Create a solution in CPP for 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 N = 3e5 + 7, M = 2e6;
const long long mod = 1e9 + 7;
inline int read() {
  int ret = 0;
  char ch = getchar();
  bool f = 1;
  for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^ '-');
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - 48;
  return f ? ret : -ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
const double EPS = 1e-15;
inline int sign(double a) { return a < -EPS ? -1 : a > EPS; }
inline int cmp(double a, double b) { return sign(a - b); }
struct P {
  double x, y;
  P() {}
  P(double _x, double _y) : x(_x), y(_y) {}
  P operator+(P p) { return {x + p.x, y + p.y}; }
  P operator-(P p) { return {x - p.x, y - p.y}; }
  P operator*(double d) { return {x * d, y * d}; }
  P operator/(double d) { return {x / d, y / d}; }
  bool operator<(P p) const {
    int c = cmp(x, p.x);
    if (c) return c == -1;
    return cmp(y, p.y) == -1;
  }
  bool operator==(P o) const { return cmp(x, o.x) == 0 && cmp(y, o.y) == 0; }
  void scan() {
    double k1, k2;
    scanf("%lf%lf", &k1, &k2);
    x = k1, y = k2;
  }
  void print() { printf("(%.0f,%.0f)", x, y); }
  double dot(P p) { return x * p.x + y * p.y; }
  double det(P p) { return x * p.y - y * p.x; }
  double distTo(P p) { return (*this - p).abs(); }
  double alpha() { return atan2(y, x); }
  double abs() { return sqrt(abs2()); }
  double abs2() { return x * x + y * y; }
  P rot90() { return P(-y, x); }
  P unit() { return *this / abs(); }
  double distTTo(P p) { return hypot(x - p.x, y - p.y); }
  int quad() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0); }
};
bool isMiddle(double a, double m, double b) {
  return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}
bool isMiddle(P a, P m, P b) {
  return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
}
bool onSeg(P p1, P p2, P q) {
  return sign(((p2.x - p1.x) * (q.y - p1.y) - (q.x - p1.x) * (p2.y - p1.y))) ==
             0 &&
         isMiddle(p1, q, p2);
}
bool onSeg_strict(P p1, P p2, P q) {
  return sign(((p2.x - p1.x) * (q.y - p1.y) - (q.x - p1.x) * (p2.y - p1.y))) ==
             0 &&
         sign((q - p1).dot(p1 - p2)) * sign((q - p2).dot(p1 - p2)) < 0;
}
P p[4][2];
int a, b, c;
pair<int, int> judge() {
  for (int i = 1; i <= 3; i++)
    for (int j = i + 1; j <= 3; j++)
      for (int k = 0; k < 2; k++)
        for (int z = 0; z < 2; z++) {
          if (p[i][k] == p[j][z]) {
            return make_pair(i, j);
          }
        }
  return make_pair(0, 0);
}
bool judge2() {
  int res1 = 0, res2 = 0;
  if (onSeg(p[a][0], p[a][1], p[c][0])) {
    res1 = 1;
  }
  if (onSeg(p[b][0], p[b][1], p[c][0])) {
    if (res1 == 1) return false;
    res1 = 2;
  }
  if (onSeg(p[a][0], p[a][1], p[c][1])) {
    res2 = 1;
    if (res1 == 1) return false;
  }
  if (onSeg(p[b][0], p[b][1], p[c][1])) {
    if (res2 == 1) return false;
    res2 = 2;
    if (res1 == 2) return false;
  }
  if (res1 + res2 != 3) return false;
  double dis1, dis2;
  if (res1 == 1) {
    dis1 = p[c][0].distTo(p[a][0]);
    dis2 = p[c][0].distTo(p[a][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
    dis1 = p[c][1].distTo(p[b][0]);
    dis2 = p[c][1].distTo(p[b][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
  } else {
    dis1 = p[c][0].distTo(p[b][0]);
    dis2 = p[c][0].distTo(p[b][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
    dis1 = p[c][1].distTo(p[a][0]);
    dis2 = p[c][1].distTo(p[a][1]);
    if (cmp(dis1, 0.0) == 0 || cmp(dis2, 0.0) == 0) return false;
    if (cmp(dis1, dis2) > 0) {
      if (cmp(dis2 / dis1, 0.25) < 0) return false;
    } else {
      if (cmp(dis1 / dis2, 0.25) < 0) return false;
    }
  }
  return true;
}
bool judge3() {
  if (p[a][0] == p[b][0]) {
    if (sign((p[a][0] - p[a][1]).dot(p[a][0] - p[b][1])) < 0) return false;
  } else if (p[a][0] == p[b][1]) {
    if (sign((p[a][0] - p[a][1]).dot(p[a][0] - p[b][0])) < 0) return false;
  } else if (p[a][1] == p[b][0]) {
    if (sign((p[a][1] - p[a][0]).dot(p[a][1] - p[b][1])) < 0) return false;
  } else if (p[a][1] == p[b][1]) {
    if (sign((p[a][1] - p[a][0]).dot(p[a][1] - p[b][0])) < 0) return false;
  }
  return true;
}
int main() {
  int t;
  pair<int, int> res;
  scanf("%d", &t);
  while (t--) {
    p[1][0].scan();
    p[1][1].scan();
    p[2][0].scan();
    p[2][1].scan();
    p[3][0].scan();
    p[3][1].scan();
    res = judge();
    if (res.first == 0) {
      puts("NO");
      continue;
    }
    a = res.first;
    b = res.second;
    c = 6 - a - b;
    if (!judge3()) {
      puts("NO");
      continue;
    }
    if (judge2())
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

```