#include <bits/stdc++.h>
struct P {
  long long int x;
  long long int y;
};
struct Seg {
  P a;
  P b;
};
bool isEqual(P const &a, P const &b) { return a.x == b.x && a.y == b.y; }
bool hasCommonPoint(Seg const &one, Seg const &two) {
  return isEqual(one.a, two.a) || isEqual(one.a, two.b) ||
         isEqual(one.b, two.a) || isEqual(one.b, two.b);
}
int getThirdSeg(std::pair<int, int> idxs) {
  if (idxs.first != 0 && idxs.second != 0) return 0;
  if (idxs.first != 1 && idxs.second != 1) return 1;
  if (idxs.first != 2 && idxs.second != 2) return 2;
  return -1;
}
std::pair<int, int> getFirstAndSecondSegment(std::vector<Seg> const &ss) {
  assert(ss.size() == 3);
  Seg one = ss[0];
  Seg two = ss[1];
  Seg three = ss[2];
  for (int i = 0; i < ss.size(); i++) {
    for (int j = i + 1; j < ss.size(); j++) {
      if (hasCommonPoint(ss[i], ss[j])) {
        return {i, j};
      }
    }
  }
  return {-1, -1};
}
long long int cross(P const &a, P const &b) {
  return std::abs(a.x * b.y - b.x * a.y);
}
long long int dot(P const &a, P const &b) { return a.x * b.x + b.y * a.y; }
P makeV(P const &a, P const &b) { return P{b.x - a.x, b.y - a.y}; }
double getMagnitude(P const &a) { return std::sqrt(a.x * a.x + a.y * a.y); }
bool isCorrectAngle(P const &a, P const &b) { return dot(a, b) >= 0; };
bool isOnLine(Seg const &line, P const &point) {
  auto first = makeV(line.a, line.b);
  auto second = makeV(line.a, point);
  if (cross(first, second) != 0) {
    return false;
  }
  if (first.x < 0 && second.x > 0 || first.x > 0 && second.x < 0) {
    return false;
  } else if (first.y < 0 && second.y > 0 || first.y > 0 && second.y < 0) {
    return false;
  }
  return true;
}
bool hasCorrectRatio(Seg const &first, Seg const &second, Seg const &third) {
  double one = getMagnitude(makeV(first.a, third.a)) /
               getMagnitude(makeV(first.a, first.b));
  double two = getMagnitude(makeV(second.a, third.b)) /
               getMagnitude(makeV(second.a, second.b));
  if ((0.1999999999999 <= one && one <= .8) &&
      (0.1999999999999 <= two && two <= .8)) {
    return true;
  }
  return false;
}
bool isA(std::vector<Seg> &ss) {
  auto segs = getFirstAndSecondSegment(ss);
  if (segs.first < 0) {
    return false;
  }
  auto first = ss[segs.first];
  auto second = ss[segs.second];
  auto thirdI = getThirdSeg(segs);
  if (thirdI < 0) {
    return false;
  }
  auto third = ss[thirdI];
  if (isEqual(first.a, second.a)) {
    std::swap(first.a, first.b);
  } else if (isEqual(first.a, second.b)) {
    std::swap(first.a, first.b);
    std::swap(second.a, second.b);
  } else if (isEqual(first.b, second.b)) {
    std::swap(second.a, second.b);
  }
  if (!isEqual(first.b, second.a)) {
    return false;
  }
  if (!isOnLine(first, third.a)) {
    std::swap(third.a, third.b);
    if (!isOnLine(first, third.a)) {
      return false;
    }
  }
  if (!isOnLine(second, third.b)) {
    return false;
  }
  if (!hasCorrectRatio(first, second, third)) {
    return false;
  }
  if (!isCorrectAngle(makeV(first.b, first.a), makeV(second.a, second.b))) {
    return false;
  }
  return true;
}
int main() {
  unsigned long long int c, i;
  long long int x, y;
  std::string output;
  std::ios::sync_with_stdio(false);
  std::cin >> c;
  std::stringstream msg;
  std::vector<std::vector<Seg>> sss;
  for (i = 0; i < c; i++) {
    std::vector<Seg> ss;
    for (int j = 0; j < 3; j++) {
      Seg s;
      std::cin >> s.a.x >> s.a.y >> s.b.x >> s.b.y;
      ss.push_back(s);
    }
    sss.push_back(ss);
  }
  for (auto &segs : sss) {
    if (isA(segs)) {
      std::cout << "YES\n";
    } else {
      std::cout << "NO\n";
    }
  }
}

### Prompt

In CPP, your task is to solve 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>
struct P {
  long long int x;
  long long int y;
};
struct Seg {
  P a;
  P b;
};
bool isEqual(P const &a, P const &b) { return a.x == b.x && a.y == b.y; }
bool hasCommonPoint(Seg const &one, Seg const &two) {
  return isEqual(one.a, two.a) || isEqual(one.a, two.b) ||
         isEqual(one.b, two.a) || isEqual(one.b, two.b);
}
int getThirdSeg(std::pair<int, int> idxs) {
  if (idxs.first != 0 && idxs.second != 0) return 0;
  if (idxs.first != 1 && idxs.second != 1) return 1;
  if (idxs.first != 2 && idxs.second != 2) return 2;
  return -1;
}
std::pair<int, int> getFirstAndSecondSegment(std::vector<Seg> const &ss) {
  assert(ss.size() == 3);
  Seg one = ss[0];
  Seg two = ss[1];
  Seg three = ss[2];
  for (int i = 0; i < ss.size(); i++) {
    for (int j = i + 1; j < ss.size(); j++) {
      if (hasCommonPoint(ss[i], ss[j])) {
        return {i, j};
      }
    }
  }
  return {-1, -1};
}
long long int cross(P const &a, P const &b) {
  return std::abs(a.x * b.y - b.x * a.y);
}
long long int dot(P const &a, P const &b) { return a.x * b.x + b.y * a.y; }
P makeV(P const &a, P const &b) { return P{b.x - a.x, b.y - a.y}; }
double getMagnitude(P const &a) { return std::sqrt(a.x * a.x + a.y * a.y); }
bool isCorrectAngle(P const &a, P const &b) { return dot(a, b) >= 0; };
bool isOnLine(Seg const &line, P const &point) {
  auto first = makeV(line.a, line.b);
  auto second = makeV(line.a, point);
  if (cross(first, second) != 0) {
    return false;
  }
  if (first.x < 0 && second.x > 0 || first.x > 0 && second.x < 0) {
    return false;
  } else if (first.y < 0 && second.y > 0 || first.y > 0 && second.y < 0) {
    return false;
  }
  return true;
}
bool hasCorrectRatio(Seg const &first, Seg const &second, Seg const &third) {
  double one = getMagnitude(makeV(first.a, third.a)) /
               getMagnitude(makeV(first.a, first.b));
  double two = getMagnitude(makeV(second.a, third.b)) /
               getMagnitude(makeV(second.a, second.b));
  if ((0.1999999999999 <= one && one <= .8) &&
      (0.1999999999999 <= two && two <= .8)) {
    return true;
  }
  return false;
}
bool isA(std::vector<Seg> &ss) {
  auto segs = getFirstAndSecondSegment(ss);
  if (segs.first < 0) {
    return false;
  }
  auto first = ss[segs.first];
  auto second = ss[segs.second];
  auto thirdI = getThirdSeg(segs);
  if (thirdI < 0) {
    return false;
  }
  auto third = ss[thirdI];
  if (isEqual(first.a, second.a)) {
    std::swap(first.a, first.b);
  } else if (isEqual(first.a, second.b)) {
    std::swap(first.a, first.b);
    std::swap(second.a, second.b);
  } else if (isEqual(first.b, second.b)) {
    std::swap(second.a, second.b);
  }
  if (!isEqual(first.b, second.a)) {
    return false;
  }
  if (!isOnLine(first, third.a)) {
    std::swap(third.a, third.b);
    if (!isOnLine(first, third.a)) {
      return false;
    }
  }
  if (!isOnLine(second, third.b)) {
    return false;
  }
  if (!hasCorrectRatio(first, second, third)) {
    return false;
  }
  if (!isCorrectAngle(makeV(first.b, first.a), makeV(second.a, second.b))) {
    return false;
  }
  return true;
}
int main() {
  unsigned long long int c, i;
  long long int x, y;
  std::string output;
  std::ios::sync_with_stdio(false);
  std::cin >> c;
  std::stringstream msg;
  std::vector<std::vector<Seg>> sss;
  for (i = 0; i < c; i++) {
    std::vector<Seg> ss;
    for (int j = 0; j < 3; j++) {
      Seg s;
      std::cin >> s.a.x >> s.a.y >> s.b.x >> s.b.y;
      ss.push_back(s);
    }
    sss.push_back(ss);
  }
  for (auto &segs : sss) {
    if (isA(segs)) {
      std::cout << "YES\n";
    } else {
      std::cout << "NO\n";
    }
  }
}

```