代码很挫就不贴
int main() {
int n, m;
int i, j, Q;
while(cin >> n >> m) {
if(n == 0 && m == 0) break;
b_sn = 0;
memset(dfn, -1, sizeof(dfn));
memset(low, 0, sizeof(low));
memset(belong, -1, sizeof(belong));
memset(p, -1, sizeof(p));
memset(fa, -1, sizeof(fa));
memset(in, false, sizeof(in));
memset(re, false, sizeof(re));
eid = 0; cnt = 0;
memset(road, -1, sizeof(road));
while(!S.empty()) S.pop();
for(i = 0; i <= n; ++ i) {
b_con[ i ].clear();//编号为i的联通分量包含的点
block[ i ].clear();//点i属于的联通分量编号,割点的话有2分量
}
for(i = 1; i <= m; ++ i) {
int u, v;
cin >> u >> v;
add(u, v, i);
add(v, u, i);
}
for(i = 1; i <= n; ++ i) if(dfn[ i ] == -1) dfscutp(i);
eid = 0;
memset(p, -1, sizeof(p));
memset(fa, -1, sizeof(fa));
for(i = 1; i <= n; ++ i) {
if(block[ i ].size() > 1) {
++ b_sn;
belong[ i ] = b_sn;
for(j = 0; j < block[ i ].size(); ++ j) {
int v = block[ i ][ j ];
add(b_sn, v, 1);
add(v, b_sn, 1);
}
}
}
qid = 0;
memset(pq, -1, sizeof(pq));
cin >> Q;
memset(vist, false, sizeof(vist));
for(i = 1; i <= Q; ++ i) {
int u, v;
scanf("%d %d", &u, &v);
u = road[ u ];
v = road[ v ];
if(u == v) ans[ i ] = 0;
else {
addQ(u, v, i);
addQ(v, u, i);
}
}
for(i = 1; i <= b_sn; ++ i) {
if(!vist[ i ]) tarjan(i, 0);
}
for(i = 1; i <= Q; ++ i) {
printf("%d\n", ans[ i ] / 2);
}
}
return 0;
}