# Python 语言程序设计（2017 年秋）

1034. Wormholes

A friend of yours, an inventor, has built a spaceship recently and wants to explore space with it. During his first voyages, he discovered that the universe is full of wormholes created by some alien race. These wormholes allow one to travel to places far, far away, but moreover, they can also send you to times long ago or in the distant future.

Having mapped these wormholes and their respective end points, you and your friend boldly decide to board his spaceship and go to some distant place you’d like to visit. Of course, you want to arrive at your destination as early as possible. The question is: what is this earliest arrival time?

### 输入格式

The first line of input contains an integer $c$ $(1 \le c \le 200)$, the number of test cases. Each test case starts with a line containing two coordinate triples $x_0, y_0, z_0$ and $x_1, y_1, z_1$, the space coordinates of your departure point and destination. The next line contains an integer $n$ $(0 \le n \le 50)$, the number of wormholes. Then follow $n$ lines, one for each wormhole, with two coordinate triples $x_s, y_s, z_s$ and $x_e, y_e, z_e$, the space coordinates of the wormhole entry and exit points, respectively, followed by two integers $t$, $d$ $(-1~000~000 \le t, d \le 1~000~000)$, the creation time $t$ of the wormhole and the time shift $d$ when traveling through the wormhole.

All coordinates are integers with absolute values smaller than or equal to $10~000$ and no two points are the same.

Note that, initially, the time is zero, and that tunneling through a wormhole happens instantly. For simplicity, the distance between two points is defined as their Euclidean distance (the square root of the sum of the squares of coordinate differences) rounded up to the nearest integer. Your friend’s spaceship travels at speed $1$.

### 输出格式

For each test case, print a single line containing an integer: the earliest time you can arrive at your destination.

### 样例

Input
2
0 0 0 100 0 0
2
1 1 0 1 2 0 -100 -2
0 1 0 100 1 0 -150 10
0 0 0 10 0 0
1
5 0 0 -5 0 0 0 0

Output
-89
10
{"ft_lang_label":"__label__en","ft_lang_prob":0.9013527,"math_prob":0.9947601,"size":2039,"snap":"2020-24-2020-29","text_gpt3_token_len":562,"char_repetition_ratio":0.12285012,"word_repetition_ratio":0.0,"special_character_ratio":0.28837666,"punctuation_ratio":0.11954023,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9634117,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-09T09:18:32Z\",\"WARC-Record-ID\":\"<urn:uuid:d817db95-5f2f-491b-9d69-1e9eb5adc1eb>\",\"Content-Length\":\"24913\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:62337a81-9ccd-4a4a-9baa-cbcf9fa2d03e>\",\"WARC-Concurrent-To\":\"<urn:uuid:0602e3e0-795f-4ad7-ab11-f1d67b801c3d>\",\"WARC-IP-Address\":\"202.120.88.23\",\"WARC-Target-URI\":\"https://acm.ecnu.edu.cn/contest/33/problem/1034/\",\"WARC-Payload-Digest\":\"sha1:5C3IH6WR2TLHJG4B3UHRYTLBZUKLLFYJ\",\"WARC-Block-Digest\":\"sha1:SXBMLYJBCQECWFPQHWRERENH6G7BCLAZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655899209.48_warc_CC-MAIN-20200709065456-20200709095456-00553.warc.gz\"}"}