#P15904. [TOPC 2025] Stapler

[TOPC 2025] Stapler

Description

Alice is selling a new model of game console in the toy store. When selling a new console, Alice uses a stapler to attach the receipt to the box.

However, the stapler pierces the box at two points, causing damage along the entire line segment between those two points. If any part of this segment (including its endpoints) overlaps with the console’s screen (including its boundary), it will be damaged and Alice must compensate for the console.

Fortunately, a laser reveals the exact position of the screen inside the box. The game console’s screen is a rectangle with sides parallel to the coordinate axes. Its bottom-left corner is at (xl,yl)(x_l, y_l) and its top-right corner is at (xr,yr)(x_r, y_r).

Alice plans to staple the box at the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). Please help her determine whether the stapler will damage the screen. If it will, stop her immediately.

Input Format

Each test contains multiple test cases. The first line contains the number of test cases tt. The description of the test cases follows.

The first line of each test case contains four integers xl,yl,xr,yrx_l, y_l, x_r, y_r, representing the coordinates of the bottom-left and top-right corners of the screen.

The second line of each test case contains four integers x1,y1,x2,y2x_1, y_1, x_2, y_2, representing the coordinates of the expected stapler penetration positions.

Output Format

For each test case, print STOP on a line if Alice will damage the screen, and print OK otherwise.

3
0 0 5 5
0 10 10 0
0 0 5 5
6 6 6 7
0 0 5 5
1 1 2 2
STOP
OK
STOP

Hint

  • 1t1041 \le t \le 10^4
  • The area of the screen is greater than 00.
  • The length of the stapler is greater than 00.
  • All coordinates are integers with absolute value at most 10410^4.