#include <bits/stdc++.h>
using namespace std;
bool zero(long long a, long long b, long long c, long long x, long long y) {
  if (a * 1ll * x + b * 1ll * y + c == 0) return true;
  return false;
}
bool dothis(long long x1, long long y1, long long x2, long long y2,
            long long x3, long long y3, long long x4, long long y4,
            long long x5, long long y5, long long x6, long long y6) {
  bool f = false;
  if (((x1 == x3) && (y1 == y3)) || ((x1 == x4) && (y1 == y4)) ||
      ((x2 == x3) && (y2 == y3)) || ((x2 == x4) && (y2 == y4)))
    f = true;
  if (!f) return f;
  long long x, xx, y, yy;
  if ((x1 == x3) && (y1 == y3)) {
    x = x2 - x1;
    y = y2 - y1;
    xx = x4 - x3;
    yy = y4 - y3;
  } else if ((x1 == x4) && (y1 == y4)) {
    x = x2 - x1;
    y = y2 - y1;
    xx = -x4 + x3;
    yy = -y4 + y3;
  } else if ((x2 == x3) && (y2 == y3)) {
    x = -x2 + x1;
    y = -y2 + y1;
    xx = x4 - x3;
    yy = y4 - y3;
  } else {
    x = -x2 + x1;
    y = -y2 + y1;
    xx = -x4 + x3;
    yy = -y4 + y3;
  }
  if ((x * 1ll * xx + y * 1ll * yy) < 0) return false;
  if ((x * 1ll * yy - y * 1ll * xx) == 0) return false;
  if ((x2 - x1) * 1ll * (y6 - y5) - (y2 - y1) * 1ll * (x6 - x5) == 0)
    return false;
  if ((x4 - x3) * 1ll * (y6 - y5) - (y4 - y3) * 1ll * (x6 - x5) == 0)
    return false;
  long long A1 = y2 - y1;
  long long B1 = x1 - x2;
  long long C1 = y1 * 1ll * (x2 - x1) - x1 * 1ll * (y2 - y1);
  long long A2 = y4 - y3;
  long long B2 = x3 - x4;
  long long C2 = y3 * 1ll * (x4 - x3) - x3 * 1ll * (y4 - y3);
  f = false;
  if ((zero(A1, B1, C1, x5, y5) && zero(A2, B2, C2, x6, y6)) ||
      (zero(A1, B1, C1, x6, y6) && zero(A2, B2, C2, x5, y5)))
    f = true;
  if (!f) return f;
  if (zero(A1, B1, C1, x5, y5)) {
    f = false;
    if ((x5 >= ((x1 < x2) ? (x1) : (x2))) &&
        (x5 <= ((x1 < x2) ? (x2) : (x1))) &&
        (x6 <= ((x3 < x4) ? (x4) : (x3))) && (x6 >= ((x3 < x4) ? (x3) : (x4))))
      f = true;
    if (!f) return f;
    x = x5;
    y = y5;
    xx = x6;
    yy = y6;
  } else {
    f = false;
    if ((x6 >= ((x1 < x2) ? (x1) : (x2))) &&
        (x6 <= ((x1 < x2) ? (x2) : (x1))) &&
        (x5 <= ((x3 < x4) ? (x4) : (x3))) && (x5 >= ((x3 < x4) ? (x3) : (x4))))
      f = true;
    if (!f) return f;
    xx = x5;
    yy = y5;
    x = x6;
    y = y6;
  }
  long long l1 = (x - x1) * 1ll * (x - x1) + (y - y1) * 1ll * (y - y1);
  long long l2 = (x - x2) * 1ll * (x - x2) + (y - y2) * 1ll * (y - y2);
  if (l1 < l2) swap(l1, l2);
  if (l2 == 0) return false;
  if (l1 > 16 * 1ll * l2) return false;
  l1 = (xx - x3) * 1ll * (xx - x3) + (yy - y3) * 1ll * (yy - y3);
  l2 = (xx - x4) * 1ll * (xx - x4) + (yy - y4) * 1ll * (yy - y4);
  if (l1 < l2) swap(l1, l2);
  if (l2 == 0) return false;
  if (l1 > 16 * 1ll * l2) return false;
  return true;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;
    scanf("%d%d%d%d%d%d%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4,
          &x5, &y5, &x6, &y6);
    if ((dothis((long long)x1, (long long)y1, (long long)x2, (long long)y2,
                (long long)x3, (long long)y3, (long long)x4, (long long)y4,
                (long long)x5, (long long)y5, (long long)x6, (long long)y6)) ||
        (dothis((long long)x1, (long long)y1, (long long)x2, (long long)y2,
                (long long)x5, (long long)y5, (long long)x6, (long long)y6,
                (long long)x3, (long long)y3, (long long)x4, (long long)y4)) ||
        (dothis((long long)x5, (long long)y5, (long long)x6, (long long)y6,
                (long long)x3, (long long)y3, (long long)x4, (long long)y4,
                (long long)x1, (long long)y1, (long long)x2, (long long)y2)))
      printf("YES\n");
    else
      printf("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;
bool zero(long long a, long long b, long long c, long long x, long long y) {
  if (a * 1ll * x + b * 1ll * y + c == 0) return true;
  return false;
}
bool dothis(long long x1, long long y1, long long x2, long long y2,
            long long x3, long long y3, long long x4, long long y4,
            long long x5, long long y5, long long x6, long long y6) {
  bool f = false;
  if (((x1 == x3) && (y1 == y3)) || ((x1 == x4) && (y1 == y4)) ||
      ((x2 == x3) && (y2 == y3)) || ((x2 == x4) && (y2 == y4)))
    f = true;
  if (!f) return f;
  long long x, xx, y, yy;
  if ((x1 == x3) && (y1 == y3)) {
    x = x2 - x1;
    y = y2 - y1;
    xx = x4 - x3;
    yy = y4 - y3;
  } else if ((x1 == x4) && (y1 == y4)) {
    x = x2 - x1;
    y = y2 - y1;
    xx = -x4 + x3;
    yy = -y4 + y3;
  } else if ((x2 == x3) && (y2 == y3)) {
    x = -x2 + x1;
    y = -y2 + y1;
    xx = x4 - x3;
    yy = y4 - y3;
  } else {
    x = -x2 + x1;
    y = -y2 + y1;
    xx = -x4 + x3;
    yy = -y4 + y3;
  }
  if ((x * 1ll * xx + y * 1ll * yy) < 0) return false;
  if ((x * 1ll * yy - y * 1ll * xx) == 0) return false;
  if ((x2 - x1) * 1ll * (y6 - y5) - (y2 - y1) * 1ll * (x6 - x5) == 0)
    return false;
  if ((x4 - x3) * 1ll * (y6 - y5) - (y4 - y3) * 1ll * (x6 - x5) == 0)
    return false;
  long long A1 = y2 - y1;
  long long B1 = x1 - x2;
  long long C1 = y1 * 1ll * (x2 - x1) - x1 * 1ll * (y2 - y1);
  long long A2 = y4 - y3;
  long long B2 = x3 - x4;
  long long C2 = y3 * 1ll * (x4 - x3) - x3 * 1ll * (y4 - y3);
  f = false;
  if ((zero(A1, B1, C1, x5, y5) && zero(A2, B2, C2, x6, y6)) ||
      (zero(A1, B1, C1, x6, y6) && zero(A2, B2, C2, x5, y5)))
    f = true;
  if (!f) return f;
  if (zero(A1, B1, C1, x5, y5)) {
    f = false;
    if ((x5 >= ((x1 < x2) ? (x1) : (x2))) &&
        (x5 <= ((x1 < x2) ? (x2) : (x1))) &&
        (x6 <= ((x3 < x4) ? (x4) : (x3))) && (x6 >= ((x3 < x4) ? (x3) : (x4))))
      f = true;
    if (!f) return f;
    x = x5;
    y = y5;
    xx = x6;
    yy = y6;
  } else {
    f = false;
    if ((x6 >= ((x1 < x2) ? (x1) : (x2))) &&
        (x6 <= ((x1 < x2) ? (x2) : (x1))) &&
        (x5 <= ((x3 < x4) ? (x4) : (x3))) && (x5 >= ((x3 < x4) ? (x3) : (x4))))
      f = true;
    if (!f) return f;
    xx = x5;
    yy = y5;
    x = x6;
    y = y6;
  }
  long long l1 = (x - x1) * 1ll * (x - x1) + (y - y1) * 1ll * (y - y1);
  long long l2 = (x - x2) * 1ll * (x - x2) + (y - y2) * 1ll * (y - y2);
  if (l1 < l2) swap(l1, l2);
  if (l2 == 0) return false;
  if (l1 > 16 * 1ll * l2) return false;
  l1 = (xx - x3) * 1ll * (xx - x3) + (yy - y3) * 1ll * (yy - y3);
  l2 = (xx - x4) * 1ll * (xx - x4) + (yy - y4) * 1ll * (yy - y4);
  if (l1 < l2) swap(l1, l2);
  if (l2 == 0) return false;
  if (l1 > 16 * 1ll * l2) return false;
  return true;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;
    scanf("%d%d%d%d%d%d%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4,
          &x5, &y5, &x6, &y6);
    if ((dothis((long long)x1, (long long)y1, (long long)x2, (long long)y2,
                (long long)x3, (long long)y3, (long long)x4, (long long)y4,
                (long long)x5, (long long)y5, (long long)x6, (long long)y6)) ||
        (dothis((long long)x1, (long long)y1, (long long)x2, (long long)y2,
                (long long)x5, (long long)y5, (long long)x6, (long long)y6,
                (long long)x3, (long long)y3, (long long)x4, (long long)y4)) ||
        (dothis((long long)x5, (long long)y5, (long long)x6, (long long)y6,
                (long long)x3, (long long)y3, (long long)x4, (long long)y4,
                (long long)x1, (long long)y1, (long long)x2, (long long)y2)))
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

```