Circle Passing
시간 제한2초메모리 제한1024 MB
2N명의 학생이 원에 둘러앉아 이웃끼리 서로 알고, 길이 N인 절친 M쌍이 추가로 연결될 때 두 학생 사이 최단 경로 길이를 Q번 구한다.
문제
It is the first day of high school for Anouk; as a warm-up activity, her sports teacher is making the class play name-learning games. There are students in the class. Most of them do not know each other, but there are pairs of best friends who do everything together. Each student has at most one best friend.
The teacher arranges all of the students in a circle, consecutively assigning each student a number from to . More specifically, for each , students and stand next to each other. Additionally, students and stand next to each other.
Since the teacher wants everyone to meet new students, best friends have to stand as far away from each other as possible, i.e. opposite each other. That is, the students forming the th pair of best friends are standing at positions and respectively, where .
The teacher selects two students and and hands a ball to student . The goal is to send the ball to student , but each student may only pass the ball to another student whose name they already know. Of course, best friends know each other's names. While the rules were explained, each student got to know the names of the two students standing directly beside them. Other than that, no one knows any other names.
The game is played times; the teacher chooses two students each time. Since the students are not paying attention, they do not learn any new names throughout the games. What is the minimum number of passes needed to get the ball from student to student in each game?
입력
The first line of input contains three integers, , and , where is the number of students in Anouk's class, is the number of pairs of best friends, and is the number of games that are played.
The second line contains integers , with describing the th pair of best friends. For each , the best friends stand at positions and respectively. Each student has at most one best friend.
The following lines each contain two integers, and , the two selected students in game .
출력
Output lines, the th line containing a single integer, the minimum number of passes needed in game .
제한
- .
- and .
- .
- .
- with .
힌트
The following two figures depict the arrangements in the first and the fourth sample. Two students are connected by an edge if they know each other's names.

In the first game of the first sample, the ball is given to student . Student passes the ball to their best friend, student . The ball reaches student after student passes it to them, needing two passes in total.