#include <bits/stdc++.h>
using namespace std;
int inmid(long long k1, long long k2, long long k3) {
  return (k1 - k3) * (k2 - k3) <= 0;
}
struct point {
  long long x, y;
  point operator+(const point &k1) const { return (point){k1.x + x, k1.y + y}; }
  point operator-(const point &k1) const { return (point){x - k1.x, y - k1.y}; }
  point operator*(long long k1) const { return (point){x * k1, y * k1}; }
  point operator/(long long k1) const { return (point){x / k1, y / k1}; }
  int operator==(const point &k1) const { return x == k1.x && y == k1.y; }
};
int inmid(point k1, point k2, point k3) {
  return inmid(k1.x, k2.x, k3.x) && inmid(k1.y, k2.y, k3.y);
}
long long cross(point k1, point k2) { return k1.x * k2.y - k1.y * k2.x; }
long long dot(point k1, point k2) { return k1.x * k2.x + k1.y * k2.y; }
struct line {
  point p[2];
  line(point k1, point k2) {
    p[0] = k1;
    p[1] = k2;
  }
  point &operator[](int k) { return p[k]; }
};
long long cross(line a, line b) { return cross(a[1] - a[0], b[1] - b[0]); }
long long dot(line a, line b) { return dot(a[1] - a[0], b[1] - b[0]); }
int t;
point p[7];
vector<line> l;
bool check(long long x, long long y) {
  if (x * 5 < y) return 0;
  if (x * 5 > y * 4) return 0;
  return 1;
}
bool slove(line a, line b, line c) {
  if (a[1] == b[1]) swap(a[0], a[1]), swap(b[0], b[1]);
  if (a[1] == b[0]) swap(a[0], a[1]);
  if (a[0] == b[1]) swap(b[0], b[1]);
  if (!(a[0] == b[0])) return 0;
  if (cross(a, b) == 0) return 0;
  if (dot(a, b) < 0) return 0;
  if (cross(a[1] - a[0], c[1] - a[0]) == 0 &&
      cross(b[1] - b[0], c[0] - b[0]) == 0) {
  } else
    swap(c[0], c[1]);
  if (!(cross(a[1] - a[0], c[1] - a[0]) == 0 &&
        cross(b[1] - b[0], c[0] - b[0]) == 0))
    return 0;
  if (!inmid(a[0], a[1], c[1])) return 0;
  if (!inmid(b[0], b[1], c[0])) return 0;
  if (!check(abs(a[0].x - c[1].x), abs(a[1].x - a[0].x))) return 0;
  if (!check(abs(a[0].y - c[1].y), abs(a[1].y - a[0].y))) return 0;
  if (!check(abs(b[0].x - c[0].x), abs(b[0].x - b[1].x))) return 0;
  if (!check(abs(b[0].y - c[0].y), abs(b[0].y - b[1].y))) return 0;
  return 1;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    l.clear();
    for (int i = 1; i <= 6; i++) scanf("%lld%lld", &p[i].x, &p[i].y);
    l.push_back({p[1], p[2]});
    l.push_back({p[3], p[4]});
    l.push_back({p[5], p[6]});
    if (slove(l[0], l[1], l[2]))
      cout << "YES" << endl;
    else if (slove(l[0], l[2], l[1]))
      cout << "YES" << endl;
    else if (slove(l[1], l[2], l[0]))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

### 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;
int inmid(long long k1, long long k2, long long k3) {
  return (k1 - k3) * (k2 - k3) <= 0;
}
struct point {
  long long x, y;
  point operator+(const point &k1) const { return (point){k1.x + x, k1.y + y}; }
  point operator-(const point &k1) const { return (point){x - k1.x, y - k1.y}; }
  point operator*(long long k1) const { return (point){x * k1, y * k1}; }
  point operator/(long long k1) const { return (point){x / k1, y / k1}; }
  int operator==(const point &k1) const { return x == k1.x && y == k1.y; }
};
int inmid(point k1, point k2, point k3) {
  return inmid(k1.x, k2.x, k3.x) && inmid(k1.y, k2.y, k3.y);
}
long long cross(point k1, point k2) { return k1.x * k2.y - k1.y * k2.x; }
long long dot(point k1, point k2) { return k1.x * k2.x + k1.y * k2.y; }
struct line {
  point p[2];
  line(point k1, point k2) {
    p[0] = k1;
    p[1] = k2;
  }
  point &operator[](int k) { return p[k]; }
};
long long cross(line a, line b) { return cross(a[1] - a[0], b[1] - b[0]); }
long long dot(line a, line b) { return dot(a[1] - a[0], b[1] - b[0]); }
int t;
point p[7];
vector<line> l;
bool check(long long x, long long y) {
  if (x * 5 < y) return 0;
  if (x * 5 > y * 4) return 0;
  return 1;
}
bool slove(line a, line b, line c) {
  if (a[1] == b[1]) swap(a[0], a[1]), swap(b[0], b[1]);
  if (a[1] == b[0]) swap(a[0], a[1]);
  if (a[0] == b[1]) swap(b[0], b[1]);
  if (!(a[0] == b[0])) return 0;
  if (cross(a, b) == 0) return 0;
  if (dot(a, b) < 0) return 0;
  if (cross(a[1] - a[0], c[1] - a[0]) == 0 &&
      cross(b[1] - b[0], c[0] - b[0]) == 0) {
  } else
    swap(c[0], c[1]);
  if (!(cross(a[1] - a[0], c[1] - a[0]) == 0 &&
        cross(b[1] - b[0], c[0] - b[0]) == 0))
    return 0;
  if (!inmid(a[0], a[1], c[1])) return 0;
  if (!inmid(b[0], b[1], c[0])) return 0;
  if (!check(abs(a[0].x - c[1].x), abs(a[1].x - a[0].x))) return 0;
  if (!check(abs(a[0].y - c[1].y), abs(a[1].y - a[0].y))) return 0;
  if (!check(abs(b[0].x - c[0].x), abs(b[0].x - b[1].x))) return 0;
  if (!check(abs(b[0].y - c[0].y), abs(b[0].y - b[1].y))) return 0;
  return 1;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    l.clear();
    for (int i = 1; i <= 6; i++) scanf("%lld%lld", &p[i].x, &p[i].y);
    l.push_back({p[1], p[2]});
    l.push_back({p[3], p[4]});
    l.push_back({p[5], p[6]});
    if (slove(l[0], l[1], l[2]))
      cout << "YES" << endl;
    else if (slove(l[0], l[2], l[1]))
      cout << "YES" << endl;
    else if (slove(l[1], l[2], l[0]))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

```