{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"Farmer John\u0027s cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasonable length. The input to this problem consists of the same input as in `Navigation Nightmare`,followed by a line containing a single integer $K$, followed by $K$ `distance queries`. Each distance query is a line of input containing two integers, giving the numbers of two farms between which FJ is interested in computing distance (measured in the length of the roads along the path between the two farms). Please answer FJ\u0027s distance queries as quickly as possible!"}},{"title":"Input","value":{"format":"MD","content":"* Line $1$: Two space-separated integers: $N$ and $M$\n\n* Lines $2 \\cdots M+1$: Each line contains four space-separated entities, $F1,F2, L,$ and $D$ that describe a road. $F1$ and $F2$ are numbers of\ntwo farms connected by a road, $L$ is its length, and $D$ is a\ncharacter that is either `N`, `E`, `S`, or `W` giving the\ndirection of the road from $F1$ to $F2$.\n\n* Line $2+M$: A single integer, $K. 1 \\leq K \\leq 10,000$\n\n* Lines $3+M \\leq 2+M+K$: Each line corresponds to a distance query and contains the indices of two farms."}},{"title":"Output","value":{"format":"MD","content":"Lines $1 \\cdots K$: For each distance query, output on a single line an integer giving the appropriate distance."}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\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\n1 4\n2 6\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e13\n3\n36\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"Farms $2$ and $6$ are $20+3+13\u003d36$ apart."}}]}