Away from College
题号:NC222387
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

The world is an undirected connected graph of vertices and edges, and each edge is in at most one simple ring. So as well known, the graph can be described as a cactus.

There are graduating stutents in the world this time. For the -th student, his/her college, dream, and life are at vertex c_i, d_i, l_i respectively. And for each student, he/she should go from his college vertex to life vertex as he/she is graduated. However, no one wants to abandon the dreams easily, so for the -th student, he/she wants to find a vertex x_i that x_i is possibly in the shortest path between c_i and d_i (there is at least one path that contains x_i, that is from c_i to d_i and that has minimum possible number of edges), and possibly in the shortest path between c_i and l_i. If multiple valid vertices, choose the one with the maximum distance(the number of edges in the shortest path) to c_i, if still multiple valid vertices, choose the one with the minimum index.

输入描述:

The first line contains three integers , denoting the number of vertices, the number of edges and the number of graduating students respectively.

Following m lines each contains two integers , denoting the edges in the graph.

Following q lines each contains three integers , denoting each student's college vertex, dream vertex and life vertex respectively.

It's guaranteed that no self-loops or multiple edges exist in the given graph and that the given graph forms a cactus.

输出描述:

Print q lines each containing two integers x_i, dis_i, denoting the chosen vertex and the distance between it and c_i respectively.
示例1

输入

复制
8 10 2
1 2
1 3
2 3
3 4
4 5
5 6
3 6
5 7
5 8
7 8
1 4 5
8 1 2

输出

复制
4 2
3 3

说明

The graph looks like:

* For the first student, vertices 1, 3, 4_{} are valid choices and we choose 4_{} as the answer.
* For the second student, vertices 3, 4, 5, 6, 8_{} are valid choices and we choose 3_{} as the answer.