{"trustable":false,"sections":[{"title":"","value":{"format":"MD","content":"有**n**个网格状的农田,每个农田之间有距离,会依次给出关系,在给出关系后询问两个农田之间的曼哈顿距离是多少?\n\n若无法判断则输出**-1**。"}},{"title":"Input","value":{"format":"MD","content":"对于每组案例:\n首先输入两个数字**n**和**m**,表示有**n**块农田,农田从**1**开始编号。\n接下来**m**行,每行给出**a,b,l,d**,**a**和**b**表示农田的编号,**l**表示之间的距离,**d**表示**b**在**a**的**d**侧(只有四种,北-**N**,南-**S**,西-**W**,东-**E**)。\n然后输入一个数字**k**,代表询问次数。\n之后输入**k**行,每行有三个数字**a,b,c**,表示在**c**行后询问**a,b**间的曼哈顿距离是多少?\n(1 \u003c\u003d M \u003c 40,000) \n(2 \u003c\u003d N \u003c\u003d 40,000)\n(1 \u003c\u003d K \u003c\u003d 10,000)"}},{"title":"Output","value":{"format":"MD","content":"**!!!多组输出,需要在每两组输出间空一行!!!**"}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre class\u003d\"sio\"\u003e7 6\n1 6 13 E\n6 3 9 E\n3 5 7 S\n4 1 3 N\n2 4 20 W\n4 7 2 S\n3\n1 6 1\n1 4 3\n2 6 6\n\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre class\u003d\"sio\"\u003e13\n-1\n10\n\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"MD","content":"这数据的图就是原图"}}]}