#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 1e5 + 5;
int n, m, q;
vector<pair<int, int>> adj[N];
int low[N], num[N], l = 0;
int com[N];
bool isBridge[N];
vector<int> nadj[N];
int par[N][17];
int ranks[N];
int in[N], out[N];
void Read()
{
cin >> n >> m >> q;
for(int i = 1; i <= m; ++i)
{
int u,v;
cin >> u >> v;
adj[u].emplace_back(v, i);
adj[v].emplace_back(u, i);
}
}
void dfs(int v, int p)
{
low[v] = num[v] = ++l;
for(auto i : adj[v])
if(i.second != p)
{
if(num[i.first])
{
low[v] = min(low[v], num[i.first]);
}
else
{
dfs(i.first, i.second);
low[v] = min(low[v], low[i.first]);
// Bridge
if(low[i.first] > num[v])
{
isBridge[i.second] = true;
}
}
}
}
void dfs_com(int v)
{
com[v] = l;
for(auto i : adj[v])
if(!com[i.first] && !isBridge[i.second]) {
dfs_com(i.first);
}
}
void _dfs(int v)
{
in[v] = ++l;
for(int i = 1; i < 17; ++i)
par[v][i] = par[par[v][i - 1]][i - 1];
for(auto i : nadj[v])
if(!ranks[i])
{
ranks[i] = ranks[v] + 1;
par[i][0] = v;
_dfs(i);
}
out[v] = l;
}
int LCA(int u, int v) {
if(ranks[u] < ranks[v])
swap(u, v);
for(int i = 16; ~i; --i)
if(ranks[par[u][i]] >= ranks[v])
u = par[u][i];
for(int i = 16; ~i; --i)
if(par[u][i] != par[v][i])
{
u = par[u][i];
v = par[v][i];
}
return u == v ? u : par[u][0];
}
int In(int x, int y) {
return in[x] <= in[y] && in[y] <= out[x];
}
int Get(int x, int y, int z, int t) {
if(!In(x, z) && !In(z, x))
return 0;
for(int i = 16; ~i; --i)
if(par[t][i] != 0 && !In(par[t][i], y))
t = par[t][i];
if(!In(t, y)) t = par[t][0];
// cout << x << " " << y << " " << z << " " << t << "\n";
return max(0, ranks[t] - max(ranks[x], ranks[z]));
}
void Solve()
{
dfs(1, -1);
l = 0;
for(int i = 1; i <= n; ++i)
if(!com[i])
{
++l;
dfs_com(i);
}
for(int i = 1; i <= n; ++i)
for(auto j : adj[i])
if(com[i] < com[j.first])
{
nadj[com[i]].emplace_back(com[j.first]);
nadj[com[j.first]].emplace_back(com[i]);
}
ranks[1] = 1;
l = 0;
_dfs(1);
while(q--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
a = com[a];
b = com[b];
c = com[c];
d = com[d];
int lcaAB = LCA(a, b);
int lcaCD = LCA(c, d);
int ans = ranks[c] + ranks[d] - 2 * ranks[lcaCD];
// cerr << ans << " ";
ans -= Get(lcaAB, a, lcaCD, c);
ans -= Get(lcaAB, a, lcaCD, d);
ans -= Get(lcaAB, b, lcaCD, c);
ans -= Get(lcaAB, b, lcaCD, d);
cout << ans << "\n";
}
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("tests.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
// cout << "Case #" << _ << endl;
Read();
Solve();
}
// cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
/*
Input:
1
abcahsdfaw
1
q i
Output:
9
*/
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBsbCA9IGxvbmcgbG9uZzsKdXNpbmcgbGQgPSBsb25nIGRvdWJsZTsKdXNpbmcgdWxsID0gdW5zaWduZWQgbG9uZyBsb25nOwoKY29uc3RleHByIGJvb2wgdHlwZXRlc3QgPSAwOwpjb25zdGV4cHIgaW50IE4gPSAxZTUgKyA1OwppbnQgbiwgbSwgcTsKdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiBhZGpbTl07CmludCBsb3dbTl0sIG51bVtOXSwgbCA9IDA7CmludCBjb21bTl07CmJvb2wgaXNCcmlkZ2VbTl07Cgp2ZWN0b3I8aW50PiBuYWRqW05dOwppbnQgcGFyW05dWzE3XTsKaW50IHJhbmtzW05dOwppbnQgaW5bTl0sIG91dFtOXTsKCnZvaWQgUmVhZCgpCnsKICAgIGNpbiA+PiBuID4+IG0gPj4gcTsKCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG07ICsraSkKICAgIHsKICAgICAgICBpbnQgdSx2OwogICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgYWRqW3VdLmVtcGxhY2VfYmFjayh2LCBpKTsKICAgICAgICBhZGpbdl0uZW1wbGFjZV9iYWNrKHUsIGkpOwogICAgfQp9Cgp2b2lkIGRmcyhpbnQgdiwgaW50IHApCnsKICAgIGxvd1t2XSA9IG51bVt2XSA9ICsrbDsKICAgIGZvcihhdXRvIGkgOiBhZGpbdl0pCiAgICAgICAgaWYoaS5zZWNvbmQgIT0gcCkgCiAgICAgICAgewogICAgICAgICAgICBpZihudW1baS5maXJzdF0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGxvd1t2XSA9IG1pbihsb3dbdl0sIG51bVtpLmZpcnN0XSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSAKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZGZzKGkuZmlyc3QsIGkuc2Vjb25kKTsKICAgICAgICAgICAgICAgIGxvd1t2XSA9IG1pbihsb3dbdl0sIGxvd1tpLmZpcnN0XSk7CgogICAgICAgICAgICAgICAgLy8gQnJpZGdlCiAgICAgICAgICAgICAgICBpZihsb3dbaS5maXJzdF0gPiBudW1bdl0pCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaXNCcmlkZ2VbaS5zZWNvbmRdID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KfQoKdm9pZCBkZnNfY29tKGludCB2KQp7CiAgICBjb21bdl0gPSBsOwogICAgZm9yKGF1dG8gaSA6IGFkalt2XSkKICAgICAgICBpZighY29tW2kuZmlyc3RdICYmICFpc0JyaWRnZVtpLnNlY29uZF0pIHsKICAgICAgICAgICAgZGZzX2NvbShpLmZpcnN0KTsKICAgICAgICB9Cn0KCnZvaWQgX2RmcyhpbnQgdikKewogICAgaW5bdl0gPSArK2w7CgogICAgZm9yKGludCBpID0gMTsgaSA8IDE3OyArK2kpCiAgICAgICAgcGFyW3ZdW2ldID0gcGFyW3Bhclt2XVtpIC0gMV1dW2kgLSAxXTsKCiAgICBmb3IoYXV0byBpIDogbmFkalt2XSkKICAgICAgICBpZighcmFua3NbaV0pCiAgICAgICAgewogICAgICAgICAgICByYW5rc1tpXSA9IHJhbmtzW3ZdICsgMTsKICAgICAgICAgICAgcGFyW2ldWzBdID0gdjsKICAgICAgICAgICAgX2RmcyhpKTsKICAgICAgICB9CiAgICAKICAgIG91dFt2XSA9IGw7Cn0KCmludCBMQ0EoaW50IHUsIGludCB2KSB7CiAgICBpZihyYW5rc1t1XSA8IHJhbmtzW3ZdKQogICAgICAgIHN3YXAodSwgdik7CiAgICAKICAgIGZvcihpbnQgaSA9IDE2OyB+aTsgLS1pKQogICAgICAgIGlmKHJhbmtzW3Bhclt1XVtpXV0gPj0gcmFua3Nbdl0pCiAgICAgICAgICAgIHUgPSBwYXJbdV1baV07CiAgICAKICAgIGZvcihpbnQgaSA9IDE2OyB+aTsgLS1pKQogICAgICAgIGlmKHBhclt1XVtpXSAhPSBwYXJbdl1baV0pCiAgICAgICAgewogICAgICAgICAgICB1ID0gcGFyW3VdW2ldOwogICAgICAgICAgICB2ID0gcGFyW3ZdW2ldOwogICAgICAgIH0KICAgIAogICAgcmV0dXJuIHUgPT0gdiA/IHUgOiBwYXJbdV1bMF07Cn0KCmludCBJbihpbnQgeCwgaW50IHkpIHsKICAgIHJldHVybiBpblt4XSA8PSBpblt5XSAmJiBpblt5XSA8PSBvdXRbeF07Cn0KCmludCBHZXQoaW50IHgsIGludCB5LCBpbnQgeiwgaW50IHQpIHsKICAgIGlmKCFJbih4LCB6KSAmJiAhSW4oeiwgeCkpCiAgICAgICAgcmV0dXJuIDA7CiAgICAKICAgIGZvcihpbnQgaSA9IDE2OyB+aTsgLS1pKQogICAgICAgIGlmKHBhclt0XVtpXSAhPSAwICYmICFJbihwYXJbdF1baV0sIHkpKQogICAgICAgICAgICB0ID0gcGFyW3RdW2ldOwogICAgCiAgICBpZighSW4odCwgeSkpIHQgPSBwYXJbdF1bMF07CiAgICAvLyBjb3V0IDw8IHggPDwgIiAiIDw8IHkgPDwgIiAiIDw8IHogPDwgIiAiIDw8IHQgPDwgIlxuIjsKCiAgICByZXR1cm4gbWF4KDAsIHJhbmtzW3RdIC0gbWF4KHJhbmtzW3hdLCByYW5rc1t6XSkpOwp9Cgp2b2lkIFNvbHZlKCkKewogICAgZGZzKDEsIC0xKTsKCiAgICBsID0gMDsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgICAgIGlmKCFjb21baV0pCiAgICAgICAgewogICAgICAgICAgICArK2w7CiAgICAgICAgICAgIGRmc19jb20oaSk7CiAgICAgICAgfQogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47ICsraSkKICAgICAgICBmb3IoYXV0byBqIDogYWRqW2ldKQogICAgICAgICAgICBpZihjb21baV0gPCBjb21bai5maXJzdF0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG5hZGpbY29tW2ldXS5lbXBsYWNlX2JhY2soY29tW2ouZmlyc3RdKTsKICAgICAgICAgICAgICAgIG5hZGpbY29tW2ouZmlyc3RdXS5lbXBsYWNlX2JhY2soY29tW2ldKTsKICAgICAgICAgICAgfQogICAgCiAgICByYW5rc1sxXSA9IDE7CiAgICBsID0gMDsKICAgIF9kZnMoMSk7CgogICAgd2hpbGUocS0tKSB7CiAgICAgICAgaW50IGEsIGIsIGMsIGQ7CiAgICAgICAgY2luID4+IGEgPj4gYiA+PiBjID4+IGQ7CiAgICAgICAgYSA9IGNvbVthXTsKICAgICAgICBiID0gY29tW2JdOwogICAgICAgIGMgPSBjb21bY107CiAgICAgICAgZCA9IGNvbVtkXTsKCiAgICAgICAgaW50IGxjYUFCID0gTENBKGEsIGIpOwogICAgICAgIGludCBsY2FDRCA9IExDQShjLCBkKTsKCiAgICAgICAgaW50IGFucyA9IHJhbmtzW2NdICsgcmFua3NbZF0gLSAyICogcmFua3NbbGNhQ0RdOwogICAgICAgIC8vIGNlcnIgPDwgYW5zIDw8ICIgIjsKICAgICAgICBhbnMgLT0gR2V0KGxjYUFCLCBhLCBsY2FDRCwgYyk7CiAgICAgICAgYW5zIC09IEdldChsY2FBQiwgYSwgbGNhQ0QsIGQpOwogICAgICAgIGFucyAtPSBHZXQobGNhQUIsIGIsIGxjYUNELCBjKTsKICAgICAgICBhbnMgLT0gR2V0KGxjYUFCLCBiLCBsY2FDRCwgZCk7CgogICAgICAgIGNvdXQgPDwgYW5zIDw8ICJcbiI7CiAgICB9Cn0KCmludDMyX3QgbWFpbigpCnsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNvdXQudGllKDApOwoKICAgIGlmIChmb3BlbigidGVzdHMuaW5wIiwgInIiKSkKICAgIHsKICAgICAgICBmcmVvcGVuKCJ0ZXN0LmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oInRlc3Qub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQoKICAgIGludCB0KDEpOwogICAgaWYgKHR5cGV0ZXN0KQogICAgICAgIGNpbiA+PiB0OwoKICAgIGZvciAoaW50IF8gPSAxOyBfIDw9IHQ7ICsrXykKICAgIHsKICAgICAgICAvLyBjb3V0IDw8ICJDYXNlICMiIDw8IF8gPDwgZW5kbDsKICAgICAgICBSZWFkKCk7CiAgICAgICAgU29sdmUoKTsKICAgIH0KICAgIC8vIGNlcnIgPDwgIlxuVGltZSBlbGFwc2VkOiAiIDw8IDEwMDAgKiBjbG9jaygpIC8gQ0xPQ0tTX1BFUl9TRUMgPDwgIm1zXG4iOwp9CgovKgpJbnB1dDoKMQphYmNhaHNkZmF3CjEKcSBpCgpPdXRwdXQ6CjkKKi8K