804_D. Expected diameter of a tree

Pasha is a good student and one of MoJaK's best friends. He always have a problem to think about. Today they had a talk about the following problem.

We have a forest (acyclic undirected graph) with n vertices and m edges. There are q queries we should answer. In each query two vertices v and u are given. Let V be the set of vertices in the connected component of the graph that contains v, and U be the set of vertices in the connected component of the graph that contains u. Let's add an edge between some vertex <image> and some vertex in <image> and compute the value d of the resulting component. If the resulting component is a tree, the value d is the diameter of the component, and it is equal to -1 otherwise. What is the expected value of d, if we choose vertices a and b from the sets uniformly at random?

Can you help Pasha to solve this problem?

The diameter of the component is the maximum distance among some pair of vertices in the component. The distance between two vertices is the minimum number of edges on some path between the two vertices.

Note that queries don't add edges to the initial forest. 

Input

The first line contains three integers n, m and q(1 ≤ n, m, q ≤ 105) — the number of vertices, the number of edges in the graph and the number of queries.

Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n), that means there is an edge between vertices ui and vi.

It is guaranteed that the given graph is a forest.

Each of the next q lines contains two integers ui and vi (1 ≤ ui, vi ≤ n) — the vertices given in the i-th query.

Output

For each query print the expected value of d as described in the problem statement.

Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Let's assume that your answer is a, and the jury's answer is b. The checker program will consider your answer correct, if <image>.

Examples

Input

3 1 2
1 3
3 1
2 3


Output

-1
2.0000000000


Input

5 2 3
2 4
4 3
4 2
4 1
2 5


Output

-1
2.6666666667
2.6666666667

Note

In the first example the vertices 1 and 3 are in the same component, so the answer for the first query is -1. For the second query there are two options to add the edge: one option is to add the edge 1 - 2, the other one is 2 - 3. In both ways the resulting diameter is 2, so the answer is 2.

In the second example the answer for the first query is obviously -1. The answer for the second query is the average of three cases: for added edges 1 - 2 or 1 - 3 the diameter is 3, and for added edge 1 - 4 the diameter is 2. Thus, the answer is <image>.

Example input:
5 2 3
2 4
4 3
4 2
4 1
2 5

3 1 2
1 3
3 1
2 3


Example output:
-1
2.6666666667
2.6666666667

-1
2.0000000000


Tags: binary search
brute force
dfs and similar
dp
sortings
trees
Difficulty rating: 2500

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
using ll = long long;
vector<int> v[N];
vector<ll> d[N], pre[N];
int n, m, q, vis[N], dis[N], mxpos, mxv;
map<pair<int, int>, ll> mp;
void dfs(int pos, int clr = 0, int dd = 0, int fa = 0) {
  vis[pos] = max(vis[pos], clr);
  dis[pos] = max(dis[pos], dd);
  if (mxv < dd) mxv = dd, mxpos = pos;
  if (clr) d[clr].push_back(dis[pos]);
  for (auto &i : v[pos])
    if (i != fa) dfs(i, clr, dd + 1, pos);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  int t1, t2, ptr = 0;
  for (int i = 1; i <= m; i++) {
    cin >> t1 >> t2;
    v[t1].push_back(t2);
    v[t2].push_back(t1);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    mxv = 0;
    mxpos = i;
    dfs(i);
    mxv = 0;
    dfs(mxpos);
    dfs(mxpos, ++ptr);
    sort(d[ptr].begin(), d[ptr].end());
    pre[ptr].push_back(0);
    for (auto &i : d[ptr]) pre[ptr].push_back(pre[ptr].back() + i);
  }
  for (int _ = 1; _ <= q; ++_) {
    int x, y;
    cin >> x >> y;
    x = vis[x];
    y = vis[y];
    if (x == y) {
      puts("-1");
      continue;
    }
    if (d[x].size() > d[y].size()) swap(x, y);
    if (mp[{x, y}]) {
      printf("%.9lf\n", mp[{x, y}] / (d[x].size() * d[y].size() * 1.0));
      continue;
    }
    ll ans = 0, mxd = max(d[x].back(), d[y].back());
    for (auto &i : d[x]) {
      int cnt =
          lower_bound(d[y].begin(), d[y].end(), mxd - i - 1) - d[y].begin();
      ans += mxd * cnt + (d[y].size() - cnt) * (i + 1) + pre[y].back() -
             pre[y][cnt];
    }
    mp[{x, y}] = ans;
    printf("%.9lf\n", mp[{x, y}] / (d[x].size() * d[y].size() * 1.0));
  }
  return 0;
}