#include <bits/stdc++.h>
using namespace std;
struct pnt {
  long long x, y;
  pnt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
};
long long dist2(const pnt& A) { return A.x * A.x + A.y * A.y; }
long long scalar(const pnt& A, const pnt& B) { return A.x * B.x + A.y * B.y; }
long long cross(const pnt& A, const pnt& B) { return A.x * B.y - A.y * B.x; }
bool operator==(const pnt& A, const pnt& B) { return A.x == B.x && A.y == B.y; }
bool operator!=(const pnt& A, const pnt& B) { return !(A == B); }
pnt operator-(const pnt& A, const pnt& B) { return pnt(A.x - B.x, A.y - B.y); }
long long lcm(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
bool in_line(const pnt& A, const pnt& B, const pnt& C) {
  pnt CB = C - B, AB = A - B;
  long long scal = scalar(CB, AB);
  if (scal >= 0) return false;
  long long a = dist2(AB), b = dist2(CB);
  long long c = abs(scal);
  long long lcm_l = lcm(a, c);
  long long lcm_r = lcm(c, b);
  long long num_l = a / lcm_l;
  long long denum_l = c / lcm_l;
  long long num_r = c / lcm_r;
  long long denum_r = b / lcm_r;
  return num_l == num_r && denum_l == denum_r;
}
struct seg {
  pnt A, B;
};
const long long MAGIC_RATIO = 4LL;
const long long MAGIC_SQ = MAGIC_RATIO * MAGIC_RATIO;
bool ok_ratio(long long one, long long two) {
  if (one >= two) swap(one, two);
  if (one == 0) return two == 0;
  return one >= (two + MAGIC_SQ - 1) / MAGIC_SQ;
}
bool ok_ratio(const pnt& A, const pnt& B, const pnt& C) {
  long long one = dist2(B - A);
  long long two = dist2(C - B);
  return ok_ratio(one, two);
}
bool solve(seg first, seg second, seg third) {
  if (first.A != second.A) swap(second.A, second.B);
  if (first.A != second.A) swap(first.A, first.B);
  if (first.A != second.A) swap(second.A, second.B);
  if (first.A != second.A) return false;
  if (!in_line(first.A, third.A, first.B)) swap(third.A, third.B);
  if (!in_line(first.A, third.A, first.B)) return false;
  if (!in_line(second.A, third.B, second.B)) return false;
  if (!ok_ratio(first.A, third.A, first.B)) return false;
  if (!ok_ratio(second.A, third.B, second.B)) return false;
  pnt v1 = first.B - first.A;
  pnt v2 = second.B - second.A;
  if (scalar(v1, v2) < 0) return false;
  if (cross(v1, v2) == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  seg A[3];
  for (int tt = 0; tt < n; tt++) {
    for (int i = 0; i < 3; i++)
      cin >> A[i].A.x >> A[i].A.y >> A[i].B.x >> A[i].B.y;
    bool result = false;
    if (solve(A[0], A[1], A[2])) result = true;
    if (solve(A[1], A[2], A[0])) result = true;
    if (solve(A[2], A[0], A[1])) result = true;
    if (result)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

### Prompt

Please provide a cpp coded solution 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;
struct pnt {
  long long x, y;
  pnt(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
};
long long dist2(const pnt& A) { return A.x * A.x + A.y * A.y; }
long long scalar(const pnt& A, const pnt& B) { return A.x * B.x + A.y * B.y; }
long long cross(const pnt& A, const pnt& B) { return A.x * B.y - A.y * B.x; }
bool operator==(const pnt& A, const pnt& B) { return A.x == B.x && A.y == B.y; }
bool operator!=(const pnt& A, const pnt& B) { return !(A == B); }
pnt operator-(const pnt& A, const pnt& B) { return pnt(A.x - B.x, A.y - B.y); }
long long lcm(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
bool in_line(const pnt& A, const pnt& B, const pnt& C) {
  pnt CB = C - B, AB = A - B;
  long long scal = scalar(CB, AB);
  if (scal >= 0) return false;
  long long a = dist2(AB), b = dist2(CB);
  long long c = abs(scal);
  long long lcm_l = lcm(a, c);
  long long lcm_r = lcm(c, b);
  long long num_l = a / lcm_l;
  long long denum_l = c / lcm_l;
  long long num_r = c / lcm_r;
  long long denum_r = b / lcm_r;
  return num_l == num_r && denum_l == denum_r;
}
struct seg {
  pnt A, B;
};
const long long MAGIC_RATIO = 4LL;
const long long MAGIC_SQ = MAGIC_RATIO * MAGIC_RATIO;
bool ok_ratio(long long one, long long two) {
  if (one >= two) swap(one, two);
  if (one == 0) return two == 0;
  return one >= (two + MAGIC_SQ - 1) / MAGIC_SQ;
}
bool ok_ratio(const pnt& A, const pnt& B, const pnt& C) {
  long long one = dist2(B - A);
  long long two = dist2(C - B);
  return ok_ratio(one, two);
}
bool solve(seg first, seg second, seg third) {
  if (first.A != second.A) swap(second.A, second.B);
  if (first.A != second.A) swap(first.A, first.B);
  if (first.A != second.A) swap(second.A, second.B);
  if (first.A != second.A) return false;
  if (!in_line(first.A, third.A, first.B)) swap(third.A, third.B);
  if (!in_line(first.A, third.A, first.B)) return false;
  if (!in_line(second.A, third.B, second.B)) return false;
  if (!ok_ratio(first.A, third.A, first.B)) return false;
  if (!ok_ratio(second.A, third.B, second.B)) return false;
  pnt v1 = first.B - first.A;
  pnt v2 = second.B - second.A;
  if (scalar(v1, v2) < 0) return false;
  if (cross(v1, v2) == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  seg A[3];
  for (int tt = 0; tt < n; tt++) {
    for (int i = 0; i < 3; i++)
      cin >> A[i].A.x >> A[i].A.y >> A[i].B.x >> A[i].B.y;
    bool result = false;
    if (solve(A[0], A[1], A[2])) result = true;
    if (solve(A[1], A[2], A[0])) result = true;
    if (solve(A[2], A[0], A[1])) result = true;
    if (result)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

```