Under construction

Still being built. Things may change

Chukjibeop

Time limit2sMemory limit1024 MB

Summary
Given M roads among N locations, find the minimum time from s to e for each query, where a 1-minute teleport may only reach locations not connected by roads.
Level

Medium5 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

A is troubled by severe traffic jams during the morning commute. A's area of activity has NN locations numbered 11 through NN and MM two-way roads, each connecting two different locations. Crossing each road takes 11 minute.

A, a skilled Taoist sorcerer, can use chukjibeop to move from any location to any other location in 11 minute. However, teleporting from the current location to a location reachable by traveling along 00 or more roads is considered cutting in line, which the sorcerers' code of ethics strictly prohibits.

Given QQ pairs of start and destination, find the minimum time to travel from the start to the destination for each pair.

Input

The first line contains the number of locations NN, the number of roads MM, and the number of queries QQ, separated by spaces. (2≤N≤1092 \le N \le 10^9; 1≤M≤2 0001 \le M \le 2\,000; 1≤Q≤5×1051 \le Q \le 5 \times 10^5)

Each of the next MM lines contains two integers uu and vv, the endpoints of a road, separated by a space. (1≤u<v≤N1 \le u \lt v \le N) No two roads have the same pair of endpoints.

Each of the next QQ lines contains a start ss and a destination ee, separated by a space. (1≤s,e≤N1 \le s, e \le N)

Output

For each pair, print the minimum time to travel from the start to the destination on its own line, for QQ lines in total.

Examples1

  1. Example 1

    Input
    5 3 5
    1 2
    1 3
    3 4
    1 1
    1 2
    1 4
    4 2
    5 1
    
    Expected output
    0
    1
    2
    2
    1