and Bengali as well.
There are N$N$ cats (numbered 1$1$ through N$N$) and M$M$ rats (numbered 1$1$ through M$M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats also want to eat the rats when they get a chance. Both the cats and the rats can only move with constant speed 1$1$.
For each valid i$i$, the i$i$-th cat is initially sleeping at a point a_i$a_i$. At a time s_i$s_i$, this cat wakes up and starts moving to a final point b_i$b_i$ with constant velocity and without any detours (so it arrives at this point at the time e_i = s_i + |a_i-b_i|$e_i = s_i + |a_i-b_i|$). After it arrives at the point b_i$b_i$, it falls asleep again.
For each valid i$i$, the i$i$-th rat is initially hiding at a point c_i$c_i$. At a time r_i$r_i$, this rat stops hiding and starts moving to a final point d_i$d_i$ in the same way as the cats ― with constant velocity and without any detours, arriving at the time q_i = r_i + |c_i-d_i|$q_i = r_i + |c_i-d_i|$ (if it does not get eaten). After it arrives at the point d_i$d_i$, it hides again.
If a cat and a rat meet each other (they are located at the same point at the same time), the cat eats the rat, the rat disappears and cannot be eaten by any other cat. A sleeping cat cannot eat a rat and a hidden rat cannot be eaten ― formally, cat i$i$ can eat rat j$j$ only if they meet at a time t$t$ satisfying s_i \le t \le e_i$s_i \le t \le e_i$ and r_j \le t \le q_j$r_j \le t \le q_j$.
Your task is to find out which rats get eaten by which cats. It is guaranteed that no two cats will meet a rat at the same time.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains two space-separated integers N$N$ and M$M$.
- N$N$ lines follow. For each i$i$ (1 \le i \le N$1 \le i \le N$), the i$i$-th of these lines contains three space-separated integers a_i$a_i$, b_i$b_i$ and s_i$s_i$.
- M$M$ more lines follow. For each i$i$ (1 \le i \le M$1 \le i \le M$), the i$i$-th of these lines contains three space-separated integers c_i$c_i$, d_i$d_i$ and r_i$r_i$.

-----Output-----
For each test case, print M$M$ lines. For each valid i$i$, the i$i$-th of these lines should contain a single integer ― the number of the cat that will eat the i$i$-th rat, or -1$-1$ if no cat will eat this rat.

-----Constraints-----
- 1 \le T \le 10$1 \le T \le 10$
- 0 \le N \le 1,000$0 \le N \le 1,000$
- 1 \le M \le 1,000$1 \le M \le 1,000$
- 1 \le a_i, b_i, s_i \le 10^9$1 \le a_i, b_i, s_i \le 10^9$ for each valid i$i$
- 1 \le c_i, d_i, r_i \le 10^9$1 \le c_i, d_i, r_i \le 10^9$ for each valid i$i$
- all initial and final positions of all cats and rats are pairwise distinct

-----Example Input-----
2
8 7
2 5 1
1 4 1
9 14 10
20 7 9
102 99 1
199 202 1
302 299 3
399 402 3
6 3 1
10 15 10
100 101 1
201 200 1
300 301 5
401 400 5
1000 1010 1020
8 8
2 8 2
12 18 2
22 28 4
32 38 4
48 42 2
58 52 3
68 62 1
78 72 3
3 6 3
13 19 3
21 25 3
31 39 3
46 43 4
59 53 2
65 61 4
79 71 2

-----Example Output-----
1
4
5
6
7
8
-1
1
2
3
4
5
6
7
8

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '# cook your dish here\ndef sort(array):\n   new_array = []\n   for i, num in enumerate(array):\n      start = 0\n      last = i\n      while start != last:\n         mid = (start + last) // 2\n         if new_array[mid][0] > num[0]:\n            end = mid\n         else:\n            start = mid + 1\n      new_array.insert(start,num)\n   return new_array\n\ntests = int(input())\nfor _ in range(tests):\n   n, m = [int(j) for j in input().split()]\n   cats, rats = [[[0] * 3 for _ in range(n)],[[0] * 3 for _ in range(m)]]\n   for i in range(n):\n      cats[i] = [int(j) * 2 for j in input().split()]\n   for i in range(m):\n      rats[i] = [int(j) * 2 for j in input().split()]\n   \n   right_cats, left_cats, right_rats, left_rats = [[],[],[],[]]\n   for i in range(n):\n      start, end, time = cats[i]\n      if end > start:\n         right_cats.append([start-time,time,end-start+time,i])\n      else:\n         left_cats.append([start+time,time,start-end+time,i])\n   for i in range(m):\n      start, end, time = rats[i]\n      if end > start:\n         right_rats.append([start-time,time,end-start+time,i])\n      else:\n         left_rats.append([start+time,time,start-end+time,i])\n   \n   #right_cats = sort(right_cats)\n   #right_rats = sort(right_rats)\n   #left_cats = sort(left_cats)\n   #left_rats = sort(left_rats)\n   \n   cat_number = [[-1,-1] for _ in range(m)]\n   \n   for rat in left_rats:\n      point, start, end, index = rat\n      for cat in left_cats:\n         #if point < cat[0]:\n         #   break\n         if point == cat[0]:\n            time_of_collision = max(cat[1],start)\n            if time_of_collision <= end and time_of_collision <= cat[2]:\n               if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n                  cat_number[index][0] = cat[3] + 1\n                  cat_number[index][1] = time_of_collision\n      for cat in right_cats:\n         #if point < cat[0]:\n         #   break\n         time_of_collision = (point - cat[0]) // 2\n         if time_of_collision >= start and time_of_collision <= end and time_of_collision >= cat[1] and time_of_collision <= cat[2]:\n            if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n               cat_number[index][0] = cat[3] + 1\n               cat_number[index][1] = time_of_collision\n   for rat in right_rats:\n      point, start, end, index = rat\n      for cat in right_cats:\n         #if point < cat[0]:\n         #   break\n         if point == cat[0]:\n            time_of_collision = max(cat[1],start)\n            if time_of_collision <= end and time_of_collision <= cat[2]:\n               if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n                  cat_number[index][0] = cat[3] + 1\n                  cat_number[index][1] = time_of_collision\n      for cat in left_cats[::-1]:\n         #if point > cat[0]:\n         #   break\n         time_of_collision = (cat[0] - point) // 2\n         if time_of_collision >= start and time_of_collision <= end and time_of_collision >= cat[1] and time_of_collision <= cat[2]:\n            if cat_number[index][0] == -1 or time_of_collision < cat_number[index][1]:\n               cat_number[index][0] = cat[3] + 1\n               cat_number[index][1] = time_of_collision\n   \n   for i in range(m):\n      print(cat_number[i][0])'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14967